Editor / app.py
Aniquel's picture
Update app.py
d6c0fbd
import os
import gradio as gr
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
# Define the function that generates the text
def generate_text(prompt, length=1500, temperature=0.5):
response = openai.Completion.create(
model="text-davinci-003",
prompt=prompt,
max_tokens=length,
temperature=temperature,
)
return response.choices[0].text.strip()
iface = gr.Interface(
fn=generate_text,
inputs=[
gr.inputs.Textbox(label="Enter Prompt Here"),
gr.inputs.Slider(label="Length", minimum=1, maximum=3000, step=1, default=1500),
gr.inputs.Slider(label="Temperature", minimum=0, maximum=1, step=0.01, default=0.5),
],
outputs=gr.outputs.Textbox(label="Generated Text"),
examples=[
["Once upon a time,"],
["In a galaxy far, far away..."],
["The meaning of life is"]
],
title="TalkGPT Amanuensis",
description="Use AI to generate text based on a prompt.",
allow_flagging=False,
analytics_enabled=True,
theme="light"
)
iface.launch()