Spaces:
Sleeping
Sleeping
File size: 2,155 Bytes
76b6f27 27bfa71 75e738f 27bfa71 75e738f 7f76d3e 2709e97 27bfa71 2709e97 27bfa71 2b14256 27bfa71 2709e97 27bfa71 2709e97 7f76d3e e71d648 2709e97 2b14256 75e738f 2709e97 75e738f 2b14256 75e738f 2709e97 75e738f 76b6f27 2709e97 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
from core import submit_query, clear_history
# Define Gradio interface
with gr.Blocks(theme=gr.themes.Soft(), css=".full-height { height: 100%; display: flex; align-items: stretch; min-height: 40px; } .full-height button { height: 100%; padding: 8px 16px; } .providers-row { height: 100%; display: flex; align-items: stretch; min-height: 40px; } .providers-row .checkbox-group { height: 100%; display: flex; flex-direction: row; align-items: center; gap: 10px; }") as demo:
gr.Markdown("# Multi-Model Chat")
gr.Markdown("Chat with OpenAI, Anthropic, or Gemini. Select providers and compare responses side by side!")
with gr.Row(elem_classes="providers-row"):
providers = gr.CheckboxGroup(choices=["OpenAI", "Anthropic", "Gemini"], label="Select Providers", value=["OpenAI"], elem_classes="checkbox-group")
with gr.Row(elem_classes="full-height"):
query = gr.Textbox(
label="Enter your query",
placeholder="e.g., What is the capital of the United States?",
scale=4,
autofocus=True # This will focus the textbox on load
)
submit_button = gr.Button("Submit", scale=1)
with gr.Row():
clear_button = gr.Button("Clear History")
with gr.Row():
openai_chatbot = gr.Chatbot(label="OpenAI", type="messages", scale=1)
anthropic_chatbot = gr.Chatbot(label="Anthropic", type="messages", scale=1)
gemini_chatbot = gr.Chatbot(label="Gemini", type="messages", scale=1)
chat_history = gr.State([])
# Handle both button click and Enter key
query.submit(
fn=submit_query,
inputs=[query, providers, chat_history],
outputs=[query, openai_chatbot, anthropic_chatbot, gemini_chatbot, chat_history]
)
submit_button.click(
fn=submit_query,
inputs=[query, providers, chat_history],
outputs=[query, openai_chatbot, anthropic_chatbot, gemini_chatbot, chat_history]
)
clear_button.click(
fn=clear_history,
inputs=[],
outputs=[openai_chatbot, anthropic_chatbot, gemini_chatbot, chat_history]
)
demo.launch()
|