Spaces:
Build error
Build error
File size: 3,043 Bytes
44198e0 3f90511 44198e0 68c6844 3f90511 44198e0 f2c01c1 3f90511 68c6844 3f90511 44198e0 3f90511 68c6844 3f90511 44198e0 3f90511 68c6844 44198e0 68c6844 3f90511 68c6844 3f90511 44198e0 3f90511 68c6844 3f90511 68c6844 44198e0 3f90511 44198e0 3f90511 68c6844 3f90511 68c6844 3f90511 68c6844 3f90511 68c6844 3f90511 68c6844 3f90511 68c6844 3f90511 68c6844 3f90511 68c6844 3f90511 44198e0 68c6844 |
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 83 84 85 86 87 |
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()
|