Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
# Set up your OpenAI API credentials
|
5 |
+
openai.api_key = ""
|
6 |
+
|
7 |
+
# Define the function to search for quotes
|
8 |
+
def search_quotes(query):
|
9 |
+
response = openai.Completion.create(
|
10 |
+
engine="text-davinci-003",
|
11 |
+
prompt=f"Search for quotes based on: {query}",
|
12 |
+
max_tokens=100,
|
13 |
+
n=5,
|
14 |
+
stop=None,
|
15 |
+
temperature=0.5,
|
16 |
+
)
|
17 |
+
quotes = response.choices[0].text.strip().split("\n")
|
18 |
+
return quotes
|
19 |
+
|
20 |
+
# Define the function to search for authors
|
21 |
+
def search_author(author):
|
22 |
+
# Code to search for author information and generate a picture
|
23 |
+
author_info = f"Author: {author}\nBio: Lorem ipsum dolor sit amet, consectetur adipiscing elit."
|
24 |
+
return author_info
|
25 |
+
|
26 |
+
# Define the Gradio interface
|
27 |
+
def gradio_interface(query):
|
28 |
+
if query.startswith("author:"):
|
29 |
+
author = query[7:].strip()
|
30 |
+
author_info = search_author(author)
|
31 |
+
return author_info
|
32 |
+
elif query.startswith("tag:"):
|
33 |
+
tag = query[4:].strip()
|
34 |
+
quotes = search_quotes(tag)
|
35 |
+
return quotes
|
36 |
+
else:
|
37 |
+
quotes = search_quotes(query)
|
38 |
+
return quotes
|
39 |
+
|
40 |
+
# Create the Gradio app
|
41 |
+
inputs = gr.inputs.Textbox(label="Chat with me!")
|
42 |
+
outputs = gr.outputs.Textbox()
|
43 |
+
|
44 |
+
gr.Interface(
|
45 |
+
fn=gradio_interface,
|
46 |
+
inputs=inputs,
|
47 |
+
outputs=outputs,
|
48 |
+
layout="vertical",
|
49 |
+
theme="compact",
|
50 |
+
).launch()
|