ababio commited on
Commit
9ae9134
1 Parent(s): 4c2a689

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
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 Gradio Interface
67
- iface = gr.Interface(
68
- fn=query_anual_report,
69
- inputs=gr.Textbox(lines=2, placeholder="Ask something..."),
70
- outputs="text",
71
- title="Annual Report Query",
72
- description="Ask questions about the annual report."
73
- )
74
-
75
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()