Spaces:
Runtime error
Runtime error
File size: 2,533 Bytes
742b2a5 d5f869d 742b2a5 8c5cf5d d5f869d 742b2a5 0b8aba9 742b2a5 0b8aba9 742b2a5 0b8aba9 742b2a5 0b8aba9 742b2a5 0b8aba9 742b2a5 142a635 742b2a5 8795165 142a635 742b2a5 e2a70cb 742b2a5 37c8f0a 742b2a5 0b8aba9 742b2a5 064a3e4 8c5cf5d 37c8f0a |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# app.py
import gradio as gr
from modules.input_handler import InputHandler
from modules.retriever import Retriever
from modules.analyzer import Analyzer
from modules.citation import CitationManager
from modules.formatter import OutputFormatter
import os
# Initialize modules
input_handler = InputHandler()
retriever = Retriever(api_key=os.getenv("TAVILY_API_KEY"))
analyzer = Analyzer(base_url="https://zxzbfrlg3ssrk7d9.us-east-1.aws.endpoints.huggingface.cloud/v1/",
api_key=os.getenv("HF_TOKEN"))
citation_manager = CitationManager()
formatter = OutputFormatter()
def research_assistant(query):
"""
Main orchestrator function that coordinates all modules
"""
try:
# Step 1: Process input
processed_query = input_handler.process_query(query)
# Step 2: Retrieve data
search_results = retriever.search(processed_query)
# Step 3: Analyze content
analysis = analyzer.analyze(query, search_results)
# Step 4: Manage citations
cited_analysis = citation_manager.add_citations(analysis, search_results)
# Step 5: Format output
formatted_output = formatter.format_response(cited_analysis, search_results)
return formatted_output
except Exception as e:
return f"An error occurred: {str(e)}"
# Create Gradio interface
with gr.Blocks(title="Research Assistant") as demo:
gr.Markdown("# 🧠 AI Research Assistant")
gr.Markdown("Enter a research topic to get a structured analysis with sources")
with gr.Row():
with gr.Column():
query_input = gr.Textbox(
label="Research Query",
placeholder="Enter your research question...",
lines=3
)
submit_btn = gr.Button("Research", variant="primary")
with gr.Column():
output = gr.Markdown(label="Analysis Results")
examples = gr.Examples(
examples=[
"Latest advancements in quantum computing",
"Impact of climate change on global agriculture",
"Recent developments in Alzheimer's treatment research"
],
inputs=query_input
)
submit_btn.click(
fn=research_assistant,
inputs=query_input,
outputs=output
)
query_input.submit(
fn=research_assistant,
inputs=query_input,
outputs=output
)
if __name__ == "__main__":
demo.launch() |