Spaces:
Build error
Build error
| import openai | |
| import gradio as gr | |
| def initialize_openai(api_key): | |
| openai.api_key = api_key | |
| def generate_text(api_key, direction, paragraphs=5, max_tokens=400): | |
| initialize_openai(api_key) | |
| response = openai.Completion.create( | |
| engine="text-davinci-003", | |
| prompt=direction, | |
| max_tokens=max_tokens * paragraphs, | |
| temperature=0.7, | |
| stop=None, | |
| n=paragraphs, | |
| ) | |
| return response.choices[0].text.strip() | |
| iface = gr.Interface( | |
| fn=generate_text, | |
| inputs=["text", "text"], | |
| outputs="text", | |
| title="OpenAI Text Generator", | |
| description="Generate text based on a given direction", | |
| live=False | |
| ) | |
| iface.launch(share=True) |