Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from search_engine import search | |
| def safe_search(query, max_results=5): | |
| try: | |
| results = search(query, max_results) | |
| formatted_results = [] | |
| for result in results: | |
| formatted_result = f""" | |
| ### [{result['title']}]({result['url']}) | |
| {result['summary']} | |
| **Source:** {result['url']} | |
| **Published:** {result.get('published_date', 'N/A')} | |
| """ | |
| formatted_results.append(formatted_result) | |
| return "\n---\n".join(formatted_results) | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Create Gradio interface | |
| demo = gr.Interface( | |
| fn=safe_search, | |
| inputs=[ | |
| gr.Textbox( | |
| label="Search Query", | |
| placeholder="Enter your search query...", | |
| lines=2 | |
| ), | |
| gr.Slider( | |
| minimum=1, | |
| maximum=10, | |
| value=5, | |
| step=1, | |
| label="Number of Results" | |
| ) | |
| ], | |
| outputs=gr.Markdown(label="Search Results"), | |
| title="π Intelligent Search Engine", | |
| description=""" | |
| An AI-powered search engine that provides intelligent summaries and insights from web content. | |
| Features: | |
| - Smart content summarization | |
| - Semantic search capabilities | |
| - Clean, readable results | |
| """, | |
| examples=[ | |
| ["Latest developments in artificial intelligence", 3], | |
| ["Climate change solutions", 5], | |
| ["Space exploration news", 4] | |
| ], | |
| theme=gr.themes.Soft() | |
| ) | |