Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,25 +1,14 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import openai
|
| 3 |
|
| 4 |
-
def
|
| 5 |
openai.api_key = api_key
|
| 6 |
response = openai.Completion.create(
|
| 7 |
engine="gpt-3.5-turbo",
|
| 8 |
-
prompt=f"Title: {story_title}\n\nIn a fantasy world, {names} embarked on
|
| 9 |
max_tokens=150
|
| 10 |
)
|
| 11 |
story = response.choices[0].text.strip()
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
inputs=[
|
| 17 |
-
gr.components.Textbox(label="Enter names (comma-separated for multiple)"),
|
| 18 |
-
gr.components.Textbox(label="Enter story title"),
|
| 19 |
-
gr.components.Textbox(label="OpenAI API Key", type="password")
|
| 20 |
-
],
|
| 21 |
-
outputs="text",
|
| 22 |
-
live=True
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
iface.launch()
|
|
|
|
|
|
|
| 1 |
import openai
|
| 2 |
|
| 3 |
+
def test_generate_story(names, story_title, api_key):
|
| 4 |
openai.api_key = api_key
|
| 5 |
response = openai.Completion.create(
|
| 6 |
engine="gpt-3.5-turbo",
|
| 7 |
+
prompt=f"Title: {story_title}\n\nIn a fantasy world, {names} embarked on a journey.",
|
| 8 |
max_tokens=150
|
| 9 |
)
|
| 10 |
story = response.choices[0].text.strip()
|
| 11 |
+
print(story)
|
| 12 |
|
| 13 |
+
# Call the function with some test values
|
| 14 |
+
test_generate_story("Alice, Bob", "The Enchanted Forest", "YOUR_OPENAI_API_KEY_HERE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|