Blessin commited on
Commit
178723a
·
1 Parent(s): e7c995c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -10
app.py CHANGED
@@ -1,15 +1,30 @@
 
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 an absurd and funny journey. {names}",
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 API key
15
- test_generate_story("Alice, Bob", "The Enchanted Forest", "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")
 
 
 
 
 
 
 
 
 
 
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()