Spaces:
Build error
Build error
File size: 690 Bytes
79bf4bb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 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) |