Agents_AI / app.py
ferferefer's picture
c
4a19c8d
import gradio as gr
import os
import threading
from research_agent import ResearchAgent
lock = threading.Lock()
def invoke(openai_api_key: str, question: str) -> str:
if not openai_api_key:
raise gr.Error("OpenAI API Key is required.")
if not question:
raise gr.Error("Question is required.")
with lock:
try:
agent = ResearchAgent(openai_api_key)
result = agent.perform_research(question)
return result
except Exception as e:
raise gr.Error(f"Error: {str(e)}")
gr.close_all()
demo = gr.Interface(
fn=invoke,
inputs=[
gr.Textbox(
label="OpenAI API Key",
type="password",
lines=1,
placeholder="Enter your OpenAI API key"
),
gr.Textbox(
label="Medical Research Question",
lines=3,
placeholder="Enter your medical research question here..."
)
],
outputs=gr.Markdown(
label="Research Results",
show_label=True
),
title="Medical Research Assistant",
description="""This AI-powered tool helps you research medical questions by:
1. Analyzing your question to identify key search terms
2. Searching PubMed Central for relevant articles
3. Analyzing the content using RAG (Retrieval Augmented Generation)
4. Providing a comprehensive answer with references to scientific literature
Please enter your medical research question above.""",
theme="default",
css=".gradio-container {max-width: 800px; margin: auto;}"
)
demo.launch()