Spaces:
Build error
Build error
Upload app.py
#1
by zym0216 - opened
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from chat import RetrievalChatbot
|
| 5 |
+
|
| 6 |
+
api_key = os.environ["OPENAI_API_KEY"]
|
| 7 |
+
api_base = os.environ["OPENAI_API_BASE"]
|
| 8 |
+
pdf_dir = "papers_all"
|
| 9 |
+
model_name = "gpt-4-1106-preview"
|
| 10 |
+
|
| 11 |
+
RetrievalChatbot = RetrievalChatbot(api_key, api_base, pdf_dir, model_name)
|
| 12 |
+
|
| 13 |
+
with gr.Blocks() as demo:
|
| 14 |
+
chatbot = gr.Chatbot()
|
| 15 |
+
msg = gr.Textbox()
|
| 16 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 17 |
+
|
| 18 |
+
def respond(message, chat_history):
|
| 19 |
+
bot_message = RetrievalChatbot.get_response(chat_history, message)
|
| 20 |
+
chat_history.append((message, bot_message))
|
| 21 |
+
return "", chat_history
|
| 22 |
+
|
| 23 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 24 |
+
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
demo.launch()
|