Nicolás Larenas commited on
Commit
7acdd8f
·
verified ·
1 Parent(s): 5d6a9b2

Create gradio_interface.py

Browse files

This file handles the Gradio UI setup for the chatbot and connects to the same AI model backend.

Files changed (1) hide show
  1. gradio_interface.py +34 -0
gradio_interface.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ai_model import query_ai_model # Import AI model query function
3
+
4
+ # Function to handle chatbot conversation
5
+ async def gradio_chatbot(text, history):
6
+ history.append((text, None))
7
+ response = await query_ai_model(text)
8
+ history[-1] = (text, response)
9
+ return history
10
+
11
+ # Gradio interface
12
+ def create_gradio_interface():
13
+ chatbot = gr.Chatbot()
14
+ textbox = gr.Textbox(placeholder="Ask a question and press Enter", show_label=False)
15
+
16
+ # Set up the Gradio interface layout
17
+ with gr.Blocks() as demo:
18
+ gr.HTML("<h1>Unified Gemini Chatbot</h1>")
19
+ chatbot.render()
20
+ textbox.render()
21
+
22
+ # Bind input textbox to chatbot response
23
+ textbox.submit(
24
+ fn=gradio_chatbot,
25
+ inputs=[textbox, chatbot],
26
+ outputs=chatbot
27
+ )
28
+
29
+ return demo
30
+
31
+ # Launch Gradio interface
32
+ def run_gradio_interface():
33
+ interface = create_gradio_interface()
34
+ interface.launch(share=True, debug=True)