import streamlit as st from transformers import pipeline from serpapi.serp_api_client import SerpApiClient def get_latest_info(query): serpapi_key = os.getenv("SERPAPI_KEY") client = SerpApiClient(serpapi_key) search = client.search({ "q": query, "engine": "google", "api_key": serpapi_key }) results = search["organic_results"] if results and len(results) > 0: return results[0]["snippet"] else: return "No relevant information found." def generate_response(prompt): model_name = "facebook/opt-125m" generator = pipeline("text-generation", model=model_name) response = generator(prompt, max_length=100, num_return_sequences=1, truncation=True)[0]['generated_text'] return response with st.spinner("Generating response..."): response = generate_response(info) st.success("Response generated successfully!") st.write("Generated Response:", response)