Editor / app.py
Aniquel's picture
Create app.py
4147471
raw
history blame
1.08 kB
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=50, temperature=0.5):
response = openai.Edit.create(
model="text-davinci-edit-001",
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=100, step=1, default=50),
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 Text Editor",
description="Use AI to generate text based on a prompt.",
allow_flagging=False,
analytics_enabled=True,
theme="light"
)
iface.launch()