Spaces:
Sleeping
Sleeping
Palbha Kulkarni (Nazwale)
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
from baseline_code import *
|
4 |
+
|
5 |
+
# Qatar Airways-style theme
|
6 |
+
custom_css = """
|
7 |
+
body { background-color: #f5f5dc; }
|
8 |
+
.gradio-container { font-family: 'Lato', sans-serif; }
|
9 |
+
h1 { color: #5c0a0a; }
|
10 |
+
textarea, .message { background-color: #fff8f0; color: #333; }
|
11 |
+
.message.user { border-left: 4px solid #5c0a0a; }
|
12 |
+
.message.bot { border-left: 4px solid #d4af37; }
|
13 |
+
button { background-color: #5c0a0a; color: white; border-radius: 10px; }
|
14 |
+
button:hover { background-color: #a01010; }
|
15 |
+
"""
|
16 |
+
|
17 |
+
# Model-specific response logic
|
18 |
+
def get_response(message, chat_history, model_choice, api_key):
|
19 |
+
reply =generate_answer(query,model_choice)
|
20 |
+
|
21 |
+
chat_history.append((message, reply))
|
22 |
+
return reply, chat_history
|
23 |
+
|
24 |
+
# Gradio app
|
25 |
+
with gr.Blocks(css=custom_css) as app:
|
26 |
+
with gr.Row():
|
27 |
+
with gr.Column(scale=1):
|
28 |
+
gr.Markdown("## ⚙️ Model Configuration")
|
29 |
+
|
30 |
+
model_choice = gr.Dropdown(
|
31 |
+
label="Choose Model",
|
32 |
+
choices=["OpenAI GPT-4", "Gemini Pro", "Together AI"],
|
33 |
+
value="OpenAI GPT-4"
|
34 |
+
)
|
35 |
+
|
36 |
+
api_key_input = gr.Textbox(
|
37 |
+
label="Enter API Key",
|
38 |
+
placeholder="Enter your OpenAI API key here...",
|
39 |
+
type="password"
|
40 |
+
)
|
41 |
+
|
42 |
+
with gr.Column(scale=3):
|
43 |
+
gr.Markdown("<h1>✈️ Qatar Airways Virtual Assistant</h1>")
|
44 |
+
chatbot = gr.Chatbot(label="Assistant", height=400)
|
45 |
+
msg = gr.Textbox(label="Your Message")
|
46 |
+
state = gr.State([])
|
47 |
+
|
48 |
+
# Main logic handler
|
49 |
+
def respond(message, chat_history, model_choice, api_key):
|
50 |
+
reply, chat_history = get_response(message, chat_history, model_choice, api_key)
|
51 |
+
return reply, chat_history
|
52 |
+
|
53 |
+
msg.submit(
|
54 |
+
respond,
|
55 |
+
[msg, state, model_choice, api_key_input],
|
56 |
+
[chatbot, state]
|
57 |
+
)
|
58 |
+
|
59 |
+
app.launch()
|