Spaces:
Runtime error
Runtime error
| # 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() |