Gradio_chat / app.py
princeta3011's picture
Update app.py
7efd3cf verified
# app.py
import gradio as gr
import asyncio
from chat_agent import SimpleChatAgent
agent = SimpleChatAgent()
async def async_chat_fn(message, history):
return await agent.handle_query(message, history)
def chat_fn(message, history):
return asyncio.run(async_chat_fn(message, history))
with gr.Blocks(css="""
#title { font-size: 2.2rem; font-weight: bold; text-align: center; margin-bottom: 0.5em; color: #2e3a59; }
#desc { font-size: 1.1rem; text-align: center; color: #6c7a92; margin-bottom: 2em; }
footer { text-align: center; font-size: 0.9rem; color: #999; margin-top: 2em; }
.gradio-container { background-color: #f9fbfc; }
""") as demo:
gr.Markdown("<div id='title'> Chat + Web Scraper Agent</div>")
gr.Markdown("<div id='desc'>Ask anything, or tell me to scrape a webpage. your custom agent logic.</div>")
with gr.Row():
with gr.Column(scale=1):
gr.ChatInterface(
fn=chat_fn,
chatbot=gr.Chatbot(show_copy_button=True),
textbox=gr.Textbox(placeholder="Type your question or paste a URL to scrape...", show_label=False),
title=None,
theme="soft",
)
gr.Markdown("<footer>Built with ❤️ using LLM + Gradio UI</footer>")
demo.launch(mcp_server = True)