Spaces:
Sleeping
Sleeping
Commit
·
919fac1
1
Parent(s):
840b958
Initial
Browse files- .gitignore +5 -0
- main.py +28 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Directory
|
2 |
+
.idea
|
3 |
+
|
4 |
+
# Files
|
5 |
+
.env
|
main.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
|
5 |
+
openai.api_key = os.environ['OPENAI_API_KEY']
|
6 |
+
|
7 |
+
|
8 |
+
def generate_story(topic):
|
9 |
+
prompt = f"Write a short, creative, and fun children's story about the following topic:\n\nTopic: {topic}\n\nStory:"
|
10 |
+
response = openai.ChatCompletion.create(
|
11 |
+
model="gpt-3.5-turbo",
|
12 |
+
messages=[{"role": "user", "content": prompt}],
|
13 |
+
max_tokens=2048,
|
14 |
+
temperature=0.1
|
15 |
+
)
|
16 |
+
story = response.choices[0].message.content.strip()
|
17 |
+
return story
|
18 |
+
|
19 |
+
|
20 |
+
iface = gr.Interface(
|
21 |
+
fn=generate_story,
|
22 |
+
inputs=gr.Textbox(label="Story Topic", placeholder="E.g., Adventures of a brave rabbit..."),
|
23 |
+
outputs=gr.Textbox(label="Generated Story"),
|
24 |
+
title="✨ UmaiMother ✨",
|
25 |
+
description="Enter a topic, and a fun story will be automatically generated for you!"
|
26 |
+
)
|
27 |
+
|
28 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
openai
|