Xhaheen commited on
Commit
d2704de
β€’
1 Parent(s): 39c50ec

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # !pip install
2
+
3
+
4
+ from pyChatGPT import ChatGPT
5
+ import os
6
+
7
+
8
+
9
+
10
+
11
+
12
+ # Save the session_token variable to the system environment
13
+ os.environ['SESSION_TOKEN'] = session_token
14
+
15
+ # Load the saved session_token value from the system environment
16
+ loaded_session_token = os.environ['SESSION_TOKEN']
17
+ def chat_hf(text,session_tokenz):
18
+
19
+
20
+ try:
21
+ # Save the session_token variable to the system environment
22
+ # os.environ['SESSION_TOKEN'] = session_token
23
+
24
+ # Load the saved session_token value from the system environment
25
+ loaded_session_token = os.environ['SESSION_TOKEN']
26
+
27
+ api = ChatGPT(session_token)
28
+ resp = api.send_message(text)
29
+
30
+
31
+ api.refresh_auth() # refresh the authorization token
32
+ api.reset_conversation() # reset the conversation
33
+ xyz = resp['message']
34
+ except:
35
+
36
+
37
+ api = ChatGPT(session_tokenz)
38
+ resp = api.send_message(text)
39
+
40
+
41
+ api.refresh_auth() # refresh the authorization token
42
+ api.reset_conversation() # reset the conversation
43
+ xyz = resp['message']
44
+
45
+ return xyz
46
+
47
+
48
+
49
+
50
+ #@title GRadio for SDK api
51
+
52
+ import gradio as gr
53
+ gr.Interface(
54
+ chat_hf,
55
+ [gr.Textbox(label = ' Input custom for ChatGPT'),
56
+ gr.Textbox(label = ' If it fails enter cusom session ')],
57
+ outputs = gr.outputs.Textbox(type="text",label="chatGPT response")
58
+ , title = "" +' ChatGpt πŸ€–πŸ’¬πŸ’» on hugginface. '+ "",
59
+ description="ChatGPT πŸ€–πŸ’¬πŸ’» is a conversational AI app that allows users to engage in natural language conversations with a virtual assistant. The app uses advanced machine learning algorithms to understand and respond to user queries in a human-like manner. With its ability to answer follow-up questions, admit mistakes, and reject inappropriate requests, ChatGPT offers a highly interactive and engaging experience. Try ChatGPT now and experience the power of language modeling in dialogue built with ❀️ @[Xhaheen](https://www.linkedin.com/in/sallu-mandya/) \n\nIf it fails enter cusom session key see video for reference refer @[Bhavesh bhat video](https://youtu.be/TdNSj_qgdFk)").launch(share = True, debug = True)