searchbar2 / app.py
Shubhy's picture
Update app.py
1dfe08c
import gradio as gr
import openai
# Set up your OpenAI API credentials
openai.api_key = "apikey"
# Define the function to search for quotes
def search_quotes(query):
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"Search for quotes based on: {query}",
max_tokens=100,
n=5,
stop=None,
temperature=0.5,
)
quotes = response.choices[0].text.strip().split("\n")
return quotes
# Define the function to search for authors
def search_author(author):
# Code to search for author information and generate a picture
author_info = f"Author: {author}\nBio: Lorem ipsum dolor sit amet, consectetur adipiscing elit."
return author_info
# Define the Gradio interface
def gradio_interface(query):
if query.startswith("author:"):
author = query[7:].strip()
author_info = search_author(author)
return author_info
elif query.startswith("tag:"):
tag = query[4:].strip()
quotes = search_quotes(tag)
return quotes
else:
quotes = search_quotes(query)
return quotes
# Create the Gradio app
inputs = gr.inputs.Textbox(label="Chat with me!")
outputs = gr.outputs.Textbox()
gr.Interface(
fn=gradio_interface,
inputs=inputs,
outputs=outputs,
layout="vertical",
theme="compact",
).launch()