GrimBot / gradio_interface.py
Nicolás Larenas
Update gradio_interface.py
a6692e9 verified
raw
history blame contribute delete
989 Bytes
import gradio as gr
from ai_model import query_ai_model # Import AI model query function
# Function to handle chatbot conversation
def gradio_chatbot(text, history):
history.append((text, None))
response = asyncio.run(query_ai_model(text))
history[-1] = (text, response)
return history
# Gradio interface
def create_gradio_interface():
chatbot = gr.Chatbot()
textbox = gr.Textbox(placeholder="Ask a question and press Enter", show_label=False)
# Set up the Gradio interface layout
with gr.Blocks() as demo:
gr.HTML("<h1>Unified Gemini Chatbot</h1>")
chatbot.render()
textbox.render()
# Bind input textbox to chatbot response
textbox.submit(
fn=gradio_chatbot,
inputs=[textbox, chatbot],
outputs=chatbot
)
return demo
# Launch Gradio interface
def run_gradio_interface():
interface = create_gradio_interface()
interface.launch(share=True, debug=True)