File size: 949 Bytes
1d18324
 
de408a2
1d18324
 
e8b689c
de408a2
 
1d18324
cdac2b0
 
de408a2
 
 
 
1d18324
 
 
 
a7d6a6b
 
1d18324
 
 
 
1c6a8c1
 
1d18324
1c6a8c1
 
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
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)