Spaces:
Sleeping
Sleeping
File size: 1,612 Bytes
7aa6874 4a19c8d 7aa6874 4a19c8d dd9a7ec 7aa6874 4a19c8d c87a829 7aa6874 4a19c8d 7aa6874 4a19c8d 7aa6874 |
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 52 53 54 55 |
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() |