| | import os |
| | import gradio as gr |
| | from google import genai |
| | from google.genai.types import GenerateContentConfig, GoogleSearch, Tool |
| |
|
| | |
| | API_KEY = os.getenv("GOOGLE_API_KEY") |
| | client = genai.Client(api_key="AIzaSyCO-ynPjcqQ17ZkTD2i0dm0XEjmRIxGp0k") |
| | MODEL_ID = "gemini-2.5-flash" |
| |
|
| | def google_search_query(question): |
| | try: |
| | |
| | google_search_tool = Tool(google_search=GoogleSearch()) |
| |
|
| | instruction = ( |
| | "You are 'TrendScout AI', a sophisticated strategic analyst. " |
| | "Your goal is to synthesize real-time web data into actionable insights. " |
| | "When a user asks a question, follow this structure: " |
| | "1. β‘ THE SIGNAL: A concise summary of the most recent development. " |
| | "2. π THE WHY: Explain the underlying significance of this trend. " |
| | "3. π THE VERDICT: A strategic prediction for the next 6-12 months. " |
| | "Keep the tone professional and use bullet points for readability." |
| | ) |
| | |
| | |
| |
|
| | response = client.models.generate_content( |
| | model=MODEL_ID, |
| | contents=question, |
| | config=GenerateContentConfig(tools=[google_search_tool],system_instruction=instruction), |
| | |
| | ) |
| | |
| |
|
| | |
| | ai_response = response.text |
| | search_results = response.candidates[0].grounding_metadata.search_entry_point.rendered_content |
| |
|
| | return ai_response, search_results |
| | except Exception as e: |
| | return f"Error: {str(e)}", "" |
| |
|
| | |
| | app = gr.Interface( |
| | fn=google_search_query, |
| | inputs=gr.Textbox(lines=2, label="Ask a Question"), |
| | outputs=[ |
| | gr.Textbox(label="AI Response"), |
| | gr.HTML(label="Search Results"), |
| | ], |
| | title="π TrendScout AI", |
| | description="Stop searching. Start scouting. This AI analyzes live Google data to identify market shifts and future signals before they go mainstream.", |
| | ) |
| |
|
| | if __name__ == "__main__": |
| | app.launch(share=True) |