Spaces:
Runtime error
Runtime error
Create app.py
#1
by Aniquel - opened
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
# Define the function that generates the text
|
| 9 |
+
def generate_text(prompt, length=50, temperature=0.5):
|
| 10 |
+
response = openai.Edit.create(
|
| 11 |
+
model="text-davinci-edit-001",
|
| 12 |
+
prompt=prompt,
|
| 13 |
+
max_tokens=length,
|
| 14 |
+
temperature=temperature
|
| 15 |
+
)
|
| 16 |
+
return response.choices[0].text.strip()
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=generate_text,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.inputs.Textbox(label="Enter Prompt Here"),
|
| 24 |
+
gr.inputs.Slider(label="Length", minimum=1, maximum=100, step=1, default=50),
|
| 25 |
+
gr.inputs.Slider(label="Temperature", minimum=0, maximum=1, step=0.01, default=0.5),
|
| 26 |
+
],
|
| 27 |
+
outputs=gr.outputs.Textbox(label="Generated Text"),
|
| 28 |
+
|
| 29 |
+
examples=[
|
| 30 |
+
["Once upon a time,"],
|
| 31 |
+
["In a galaxy far, far away..."],
|
| 32 |
+
["The meaning of life is"]
|
| 33 |
+
],
|
| 34 |
+
title="TalkGPT Text Editor",
|
| 35 |
+
description="Use AI to generate text based on a prompt.",
|
| 36 |
+
allow_flagging=False,
|
| 37 |
+
analytics_enabled=True,
|
| 38 |
+
theme="light"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
iface.launch()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|