Spaces:
Sleeping
Sleeping
File size: 1,982 Bytes
64e077c |
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 |
import streamlit as st
import openai
from serpapi import GoogleSearch
# Set up your OpenAI API key
openai.api_key = "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"
# Define a function to search images using GoogleSearch API
def search_images(query):
params = {
"engine": "google",
"tbm": "isch",
"q": query,
"api_key": "bebb5ff17b2faddf1eec1636ac6dc093d1892da946c28df6a41c3425f09bb4a3"
}
search = GoogleSearch(params)
data = search.get_dict()
if data.get('search_metadata').get('status') == 'Success':
results = data.get('images_results')
if results:
images = []
for result in results:
images.append(result['original'])
return images[:10]
else:
return "No results found."
else:
return "Search failed. Please try again later."
# Define a function to generate a response to a given question using OpenAI
def generate_response(question):
response = openai.Completion.create(
engine="text-davinci-002",
prompt=question,
temperature=0.5,
max_tokens=1024,
n=1,
stop=None,
)
message = response.choices[0].text.strip()
return message
# Set up the Streamlit app
st.title("Welcome to Tourism AI Chatbot")
st.write("Please enter your tourism related query below:")
# Get user input and generate response
query = st.text_area("Your question here")
if st.button("Get Answer"):
response = generate_response(query)
st.write(response)
# Set up the Streamlit app for image search
st.title("Image Search using Google API")
st.write("Please enter your search query below:")
# Get user input and display image results
query = st.text_input("Search images here")
if st.button("Search"):
images = search_images(query)
if type(images) == str:
st.write(images)
else:
for image in images:
st.image(image, use_column_width=True)
|