import gradio as gr
from config import ui_config
from pathlib import Path
# UI function: only handles UI, not workflow logic
def create_app(chat_fn, clear_fn):
"""
Create the Gradio UI for SupportFlowX.
chat_fn: function to handle chat (inputs: user_message, history, api_key)
clear_fn: function to clear chat (no inputs)
Returns: gr.Blocks object
"""
base_dir = Path(__file__).parent.parent
css_path = base_dir / "ui" / "theme.css"
with open(css_path, "r", encoding="utf-8") as f:
custom_css = f.read()
with gr.Blocks(
title=ui_config.APP_TITLE,
css=custom_css,
theme=gr.themes.Soft()
) as app:
gr.HTML(f"""
""")
with gr.Row(elem_classes="main-container animate-fade-in"):
with gr.Column(scale=3):
gr.HTML(f"""
{ui_config.WELCOME_TITLE}
{ui_config.WELCOME_MESSAGE}
""")
with gr.Column(scale=1):
gr.Image(
ui_config.COVER_PATH,
height=200,
show_label=False,
container=False,
show_download_button=False
)
with gr.Row(elem_classes="main-container"):
with gr.Column(scale=3, elem_classes="chat-container card-hover"):
chatbot = gr.Chatbot(
type='messages',
label="💬 Chat with our Cafe Assistant",
height=400,
elem_classes="chatbot",
show_copy_button=True
)
with gr.Column(elem_classes="input-area"):
msg = gr.Textbox(
label="💭 What can I help you with today?",
placeholder="Ask about our menu, prices, promotions, or table availability...",
lines=1,
scale=7
)
with gr.Row():
send_btn = gr.Button(
"📤 Send Message",
scale=2,
elem_classes="send-button",
variant="primary"
)
clear_btn = gr.Button(
"🗑️ Clear Chat",
scale=1,
elem_classes="clear-button",
variant="secondary"
)
with gr.Column(elem_classes="examples-container"):
gr.HTML('
""")
with gr.Column(elem_classes="api-key-container"):
api_key_box = gr.Textbox(
label="🔑 Gemini API Key",
placeholder="Enter your Gemini API key here...",
type="password",
info="Get your API key from https://makersuite.google.com/app/apikey",
lines=1
)
with gr.Column(elem_classes="log-container"):
gr.HTML('