Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789101112131415import openaidef test_generate_story(names, story_title, api_key):openai.api_key = api_keyresponse = openai.Completion.create(engine="gpt-3.5-turbo",prompt=f"Title: {story_title}\n\nIn a fantasy world, {names} embarked on an absurd and funny journey. {names}",max_tokens=150)story = response.choices[0].text.strip()print(story)# Call the function with some test values# Test API keytest_generate_story("Alice, Bob", "The Enchanted Forest", "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")123456789101112131415161718192021222324252627282930import gradio as grimport openaidef generate_story(names, story_title, api_key):openai.api_key = api_keymessages = [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": f"Title: {story_title}. In a fantasy world, {names} embarked on an absurd and funny journey. {names}"}]response = openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=messages)story = response.choices[0].message['content']return storyiface = gr.Interface(fn=generate_story,inputs=[gr.components.Textbox(label="Enter names (comma-separated for multiple)"),gr.components.Textbox(label="Enter story title"),gr.components.Textbox(label="OpenAI API Key", type="password")],outputs="text",live=True)iface.launch()
app.py+25-10