Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
from getpass import getpass
|
| 3 |
import gradio as gr
|
|
|
|
|
|
|
| 4 |
|
| 5 |
pinecone_api_key = os.getenv("PINECONE_API_KEY") or getpass("Enter your Pinecone API Key: ")
|
| 6 |
openai_api_key = os.getenv("OPENAI_API_KEY") or getpass("Enter your OpenAI API Key: ")
|
|
@@ -63,13 +65,28 @@ def query_anual_report(query):
|
|
| 63 |
response = query_engine.query(query)
|
| 64 |
return response.response
|
| 65 |
|
| 66 |
-
# Define
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
from getpass import getpass
|
| 3 |
import gradio as gr
|
| 4 |
+
import random
|
| 5 |
+
import time
|
| 6 |
|
| 7 |
pinecone_api_key = os.getenv("PINECONE_API_KEY") or getpass("Enter your Pinecone API Key: ")
|
| 8 |
openai_api_key = os.getenv("OPENAI_API_KEY") or getpass("Enter your OpenAI API Key: ")
|
|
|
|
| 65 |
response = query_engine.query(query)
|
| 66 |
return response.response
|
| 67 |
|
| 68 |
+
# Define the chat functions
|
| 69 |
+
def user(user_message, history):
|
| 70 |
+
return "", history + [[user_message, None]]
|
| 71 |
+
|
| 72 |
+
def bot(history):
|
| 73 |
+
bot_message = query_anual_report(history[-1][0])
|
| 74 |
+
history[-1][1] = ""
|
| 75 |
+
for character in bot_message:
|
| 76 |
+
history[-1][1] += character
|
| 77 |
+
time.sleep(0.05)
|
| 78 |
+
yield history
|
| 79 |
+
|
| 80 |
+
# Define Gradio Blocks interface
|
| 81 |
+
with gr.Blocks() as demo:
|
| 82 |
+
chatbot = gr.Chatbot()
|
| 83 |
+
msg = gr.Textbox()
|
| 84 |
+
clear = gr.Button("Clear")
|
| 85 |
+
|
| 86 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
| 87 |
+
bot, chatbot, chatbot
|
| 88 |
+
)
|
| 89 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
demo.launch()
|