Spaces:
Paused
Paused
Upload app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import os
|
2 |
os.environ['OPENAI_API_KEY'] = "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"
|
3 |
import openai
|
@@ -25,7 +26,6 @@ docs.append(doc)
|
|
25 |
|
26 |
|
27 |
# define LLM
|
28 |
-
|
29 |
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003"))
|
30 |
|
31 |
# define prompt helper
|
@@ -96,30 +96,41 @@ class Chatbot:
|
|
96 |
|
97 |
bot = Chatbot("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", index=index)
|
98 |
|
|
|
99 |
import gradio as gr
|
100 |
import time
|
101 |
|
102 |
-
with gr.Blocks() as demo:
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
-
|
112 |
-
last_user_message = history[-1][0]
|
113 |
-
agent_message = bot.generate_response(last_user_message)
|
114 |
-
history[-1][1] = agent_message ["content"]
|
115 |
-
time.sleep(1)
|
116 |
-
return history
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
122 |
|
|
|
|
|
123 |
|
124 |
if __name__ == "__main__":
|
125 |
-
demo.launch()
|
|
|
1 |
+
|
2 |
import os
|
3 |
os.environ['OPENAI_API_KEY'] = "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"
|
4 |
import openai
|
|
|
26 |
|
27 |
|
28 |
# define LLM
|
|
|
29 |
llm_predictor = LLMPredictor(llm=OpenAI(temperature=0, model_name="text-davinci-003"))
|
30 |
|
31 |
# define prompt helper
|
|
|
96 |
|
97 |
bot = Chatbot("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", index=index)
|
98 |
|
99 |
+
|
100 |
import gradio as gr
|
101 |
import time
|
102 |
|
103 |
+
with gr.Blocks(theme='SebastianBravo/simci_css') as demo:
|
104 |
+
with gr.Column(scale=4):
|
105 |
+
title = 'GoChat247 AI BOT'
|
106 |
+
chatbot = gr.Chatbot(label='GoChat247 AI BOT')
|
107 |
+
msg = gr.Textbox()
|
108 |
+
clear = gr.Button("Clear")
|
109 |
+
|
110 |
+
|
111 |
+
def user(user_message, history):
|
112 |
+
return "", history + [[user_message, None]]
|
113 |
+
|
114 |
+
def agent(history):
|
115 |
+
last_user_message = history[-1][0]
|
116 |
+
agent_message = bot.generate_response(last_user_message)
|
117 |
+
history[-1][1] = agent_message ["content"]
|
118 |
+
time.sleep(1)
|
119 |
+
return history
|
120 |
+
|
121 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(agent, chatbot, chatbot)
|
122 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
123 |
+
|
124 |
+
# handling dark_theme
|
125 |
|
126 |
+
import webbrowser
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
+
def apply_dark_theme(url):
|
129 |
+
if not url.endswith('?__theme=dark'):
|
130 |
+
webbrowser.open_new(url + '?__theme=dark')
|
|
|
131 |
|
132 |
+
gradioURL = 'http://localhost:7860/'
|
133 |
+
apply_dark_theme(gradioURL)
|
134 |
|
135 |
if __name__ == "__main__":
|
136 |
+
demo.launch()
|