Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,30 @@
|
|
|
|
1 |
import openai
|
2 |
|
3 |
-
def
|
4 |
openai.api_key = api_key
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
)
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import openai
|
3 |
|
4 |
+
def generate_story(names, story_title, api_key):
|
5 |
openai.api_key = api_key
|
6 |
+
messages = [
|
7 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
8 |
+
{"role": "user", "content": f"Title: {story_title}. In a fantasy world, {names} embarked on an absurd and funny journey. {names}"}
|
9 |
+
]
|
10 |
+
|
11 |
+
response = openai.ChatCompletion.create(
|
12 |
+
model="gpt-3.5-turbo",
|
13 |
+
messages=messages
|
14 |
)
|
15 |
+
|
16 |
+
story = response.choices[0].message['content']
|
17 |
+
return story
|
18 |
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=generate_story,
|
21 |
+
inputs=[
|
22 |
+
gr.components.Textbox(label="Enter names (comma-separated for multiple)"),
|
23 |
+
gr.components.Textbox(label="Enter story title"),
|
24 |
+
gr.components.Textbox(label="OpenAI API Key", type="password")
|
25 |
+
],
|
26 |
+
outputs="text",
|
27 |
+
live=True
|
28 |
+
)
|
29 |
+
|
30 |
+
iface.launch()
|