Spaces:
Build error
Build error
import gradio as gr | |
from search_engine import search | |
def format_search_results(results): | |
"""Format search results into a clean markdown output""" | |
if 'error' in results: | |
return f"β Error: {results['error']}" | |
output = [] | |
# Add insights section | |
if 'insights' in results and results['insights']: | |
output.append("# π Latest Developments Summary\n") | |
output.append(results['insights']) | |
output.append("\n") | |
# Add key points section | |
if 'key_points' in results and results['key_points']: | |
output.append("# π‘ Key Points\n") | |
for point in results['key_points'][:5]: # Limit to top 5 points | |
output.append(f"β’ {point}\n") | |
output.append("\n") | |
# Add detailed results section | |
if 'results' in results and results['results']: | |
output.append("# π Detailed Findings\n") | |
for i, result in enumerate(results['results'], 1): | |
output.append(f"## {i}. {result.get('title', 'No Title')}\n") | |
if 'url' in result: | |
output.append(f"π [Source]({result['url']})\n") | |
if 'summary' in result: | |
output.append(f"\n{result['summary']}\n") | |
if 'key_points' in result and result['key_points']: | |
output.append("\nKey Takeaways:") | |
for point in result['key_points'][:3]: # Limit to top 3 points per result | |
output.append(f"β’ {point}") | |
output.append("\n") | |
# Add follow-up questions section | |
if 'follow_up_questions' in results and results['follow_up_questions']: | |
output.append("# β Suggested Follow-up Questions\n") | |
for question in results['follow_up_questions']: | |
output.append(f"β’ {question}\n") | |
return "\n".join(output) | |
def search_and_format(query): | |
"""Search and format results""" | |
if not query.strip(): | |
return "Please enter a search query" | |
try: | |
results = search(query) | |
return format_search_results(results) | |
except Exception as e: | |
return f"β Error performing search: {str(e)}" | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=search_and_format, | |
inputs=gr.Textbox( | |
label="Enter your search query", | |
placeholder="Example: Latest developments in quantum computing" | |
), | |
outputs=gr.Markdown(label="Search Results"), | |
title="AI-Powered Research Assistant", | |
description=""" | |
This tool helps you research topics by: | |
1. Finding relevant information from multiple sources | |
2. Summarizing key findings | |
3. Extracting important points | |
4. Suggesting follow-up questions | |
Try searching for topics in technology, science, or any other field! | |
""", | |
examples=[ | |
["Latest developments in quantum computing"], | |
["Artificial intelligence breakthroughs"], | |
["Climate change solutions"], | |
["Space exploration advancements"], | |
], | |
theme=gr.themes.Soft() | |
) | |
# Launch for Spaces | |
iface.launch() | |