Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,67 +1,43 @@
|
|
1 |
-
import gradio as gr
|
2 |
import openai
|
3 |
-
import
|
4 |
-
|
5 |
-
|
|
|
6 |
|
7 |
-
def
|
8 |
-
|
|
|
|
|
|
|
9 |
response = openai.Completion.create(
|
10 |
-
|
11 |
-
prompt=
|
12 |
-
max_tokens=
|
13 |
)
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
17 |
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
{"role": "user", "content": prompt_content}
|
31 |
-
]
|
32 |
-
|
33 |
-
response = openai.ChatCompletion.create(
|
34 |
-
model="gpt-3.5-turbo",
|
35 |
-
messages=messages
|
36 |
)
|
37 |
-
|
38 |
-
story = response.choices[0].message['content']
|
39 |
-
|
40 |
-
# Split story into four paragraphs
|
41 |
-
paragraphs = story.split('\n')[:4]
|
42 |
-
|
43 |
-
# Extract character type and action from each paragraph and create DALLE prompts
|
44 |
-
dalle_prompts = []
|
45 |
-
for para in paragraphs:
|
46 |
-
character_type, action = infer_character_and_action(api_key, para)
|
47 |
-
dalle_prompt = create_dalle_prompt(character_type, action)
|
48 |
-
dalle_prompts.append(dalle_prompt)
|
49 |
-
|
50 |
-
return story, dalle_prompts
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
inputs=[
|
55 |
-
gr.components.Textbox(label="Enter name (Example: Ella)"),
|
56 |
-
gr.components.Textbox(label="Enter story title (Example: The Enchanted Locket)"),
|
57 |
-
gr.components.Radio(["for children", "absurd and humorous"], label="Story Type"),
|
58 |
-
gr.components.Textbox(label="OpenAI API Key", type="password")
|
59 |
-
],
|
60 |
-
outputs=[
|
61 |
-
"text",
|
62 |
-
"text"
|
63 |
-
],
|
64 |
-
live=True
|
65 |
-
)
|
66 |
|
67 |
-
|
|
|
|
|
|
1 |
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Initialize OpenAI API
|
5 |
+
openai.api_key = "YOUR_OPENAI_API_KEY"
|
6 |
|
7 |
+
def ask_god(question):
|
8 |
+
# Detailed prompt for God to give humorous or sarcastic replies based on various theologies
|
9 |
+
prompt = f"Dear God, often portrayed across various theologies and religions with a sense of humor and sarcasm: {question}"
|
10 |
+
|
11 |
+
# Use GPT-3.5 Turbo to get the response
|
12 |
response = openai.Completion.create(
|
13 |
+
engine="gpt-3.5-turbo",
|
14 |
+
prompt=prompt,
|
15 |
+
max_tokens=100
|
16 |
)
|
17 |
+
|
18 |
+
# Extract the response text and return
|
19 |
+
answer = response.choices[0].text.strip()
|
20 |
+
return answer
|
21 |
|
22 |
+
# Gradio Interface
|
23 |
+
def gradio_interface():
|
24 |
+
# Define input and output components for Gradio
|
25 |
+
input_component = gr.inputs.Textbox(lines=5, placeholder="Enter your question to God...")
|
26 |
+
output_component = gr.outputs.Textbox(label="God's Reply")
|
27 |
|
28 |
+
# Create the Gradio interface
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=ask_god,
|
31 |
+
inputs=input_component,
|
32 |
+
outputs=output_component,
|
33 |
+
live=True,
|
34 |
+
title="Ask God",
|
35 |
+
description="Get humorous or sarcastic replies from God based on various theologies. Powered by GPT-3.5 Turbo.",
|
36 |
+
theme="huggingface"
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
# Launch the Gradio interface (for Hugging Face Spaces, use `share=True`)
|
40 |
+
iface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
if __name__ == "__main__":
|
43 |
+
gradio_interface()
|