Spaces:
Build error
Build error
File size: 2,873 Bytes
44198e0 3f90511 44198e0 3f90511 44198e0 f2c01c1 3f90511 44198e0 3f90511 44198e0 3f90511 44198e0 3f90511 44198e0 3f90511 44198e0 3f90511 44198e0 3f90511 44198e0 3f90511 |
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_results(results):
"""Format search results in a user-friendly way"""
if 'error' in results:
return f"β Error: {results['error']}"
output = []
# Add insights section
if 'insights' in results and results['insights']:
output.append("# π‘ Key Insights\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 i, point in enumerate(results['key_points'], 1):
output.append(f"{i}. {point}\n")
output.append("\n")
# Add detailed results section
if 'results' in results and results['results']:
output.append("# π Detailed Results\n")
for i, result in enumerate(results['results'], 1):
output.append(f"## {i}. [{result['title']}]({result['url']})\n")
if 'description' in result and result['description']:
output.append(f"*{result['description']}*\n")
if 'summary' in result and result['summary']:
output.append(f"{result['summary']}\n")
if 'key_points' in result and result['key_points']:
output.append("\nHighlights:\n")
for point in result['key_points']:
output.append(f"- {point}\n")
output.append("\n")
# Add follow-up questions section
if 'follow_up_questions' in results and results['follow_up_questions']:
output.append("# β Related 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"""
try:
results = search(query)
return format_results(results)
except Exception as e:
return f"β Error: {str(e)}"
# Create the Gradio interface
interface = gr.Interface(
fn=search_and_format,
inputs=gr.Textbox(
label="Enter your search query",
placeholder="What would you like to learn about?",
lines=2
),
outputs=gr.Markdown(
label="Search Results",
show_label=True
),
title="π AI-Powered Web Search",
description="""
This search engine uses AI to:
- Find relevant web pages
- Extract key information
- Generate insights and summaries
- Suggest follow-up questions
""",
examples=[
["What is quantum computing?"],
["Latest developments in artificial intelligence"],
["How does blockchain technology work?"],
["Explain machine learning in simple terms"],
],
theme=gr.themes.Soft()
)
# Launch the app
if __name__ == "__main__":
interface.launch()
|