Spaces:
Runtime error
Runtime error
Commit ·
0953d01
1
Parent(s): 71010fb
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
-
from gradio.components import Textbox, Image,
|
| 4 |
|
| 5 |
# Set up OpenAI API credentials
|
| 6 |
openai.api_key = "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"
|
|
@@ -12,11 +12,10 @@ model = gr.Interface.load(model_path)
|
|
| 12 |
|
| 13 |
base_prompt = "limit is 36 words"
|
| 14 |
|
| 15 |
-
|
| 16 |
# Define the OpenAI prompt completion function
|
| 17 |
def generate_text(prompt):
|
| 18 |
response = openai.Completion.create(
|
| 19 |
-
model=
|
| 20 |
prompt=f"{prompt}\n\nQ: {base_prompt}\nA:",
|
| 21 |
max_tokens=60,
|
| 22 |
n=1,
|
|
@@ -35,9 +34,13 @@ def generate_image(prompt):
|
|
| 35 |
|
| 36 |
# Define the Gradio interface
|
| 37 |
prompt_input = Textbox("Enter a prompt", lines=3)
|
| 38 |
-
text_output =
|
| 39 |
image_output = Image()
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
iface = gr.Interface(
|
| 42 |
generate_image,
|
| 43 |
inputs=prompt_input,
|
|
@@ -46,12 +49,7 @@ iface = gr.Interface(
|
|
| 46 |
description="Generates an image based on a prompt using OpenAI's GPT-3 and DALL-E models."
|
| 47 |
)
|
| 48 |
|
| 49 |
-
# Update the output boxes with the generated text and image
|
| 50 |
-
def update_text_output(text, image_url):
|
| 51 |
-
text_output.text = text
|
| 52 |
-
text_output.style['font-size'] = '8px' # Change the font size here
|
| 53 |
-
|
| 54 |
iface.interface_result_hooks = [update_text_output]
|
| 55 |
|
| 56 |
# Launch the interface
|
| 57 |
-
iface.launch()
|
|
|
|
| 1 |
import openai
|
| 2 |
import gradio as gr
|
| 3 |
+
from gradio.components import Textbox, Image, Textarea
|
| 4 |
|
| 5 |
# Set up OpenAI API credentials
|
| 6 |
openai.api_key = "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"
|
|
|
|
| 12 |
|
| 13 |
base_prompt = "limit is 36 words"
|
| 14 |
|
|
|
|
| 15 |
# Define the OpenAI prompt completion function
|
| 16 |
def generate_text(prompt):
|
| 17 |
response = openai.Completion.create(
|
| 18 |
+
model="text-davinci-003",
|
| 19 |
prompt=f"{prompt}\n\nQ: {base_prompt}\nA:",
|
| 20 |
max_tokens=60,
|
| 21 |
n=1,
|
|
|
|
| 34 |
|
| 35 |
# Define the Gradio interface
|
| 36 |
prompt_input = Textbox("Enter a prompt", lines=3)
|
| 37 |
+
text_output = Textarea("", placeholder="Generated text will appear here.", rows=5)
|
| 38 |
image_output = Image()
|
| 39 |
|
| 40 |
+
def update_text_output(text, image_url):
|
| 41 |
+
# Append the generated text to the existing value of the output textbox
|
| 42 |
+
text_output.value += "\n" + text
|
| 43 |
+
|
| 44 |
iface = gr.Interface(
|
| 45 |
generate_image,
|
| 46 |
inputs=prompt_input,
|
|
|
|
| 49 |
description="Generates an image based on a prompt using OpenAI's GPT-3 and DALL-E models."
|
| 50 |
)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
iface.interface_result_hooks = [update_text_output]
|
| 53 |
|
| 54 |
# Launch the interface
|
| 55 |
+
iface.launch()
|