Spaces:
Runtime error
Runtime error
Commit ·
7d52c76
1
Parent(s): 731282b
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,10 +12,11 @@ model = gr.Interface.load(model_path)
|
|
| 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,19 +35,9 @@ def generate_image(prompt):
|
|
| 34 |
|
| 35 |
# Define the Gradio interface
|
| 36 |
prompt_input = Textbox("Enter a prompt", lines=3)
|
| 37 |
-
text_output = Label("
|
| 38 |
image_output = Image()
|
| 39 |
|
| 40 |
-
# Initialize a variable to store the previous messages
|
| 41 |
-
previous_messages = ""
|
| 42 |
-
|
| 43 |
-
def update_text_output(text, image_url):
|
| 44 |
-
global previous_messages
|
| 45 |
-
# Concatenate the generated text with the previous messages
|
| 46 |
-
previous_messages += "\n" + text
|
| 47 |
-
# Set the text of the output Label to the concatenated string
|
| 48 |
-
text_output.text = previous_messages
|
| 49 |
-
|
| 50 |
iface = gr.Interface(
|
| 51 |
generate_image,
|
| 52 |
inputs=prompt_input,
|
|
@@ -55,7 +46,12 @@ iface = gr.Interface(
|
|
| 55 |
description="Generates an image based on a prompt using OpenAI's GPT-3 and DALL-E models."
|
| 56 |
)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
iface.interface_result_hooks = [update_text_output]
|
| 59 |
|
| 60 |
# Launch the interface
|
| 61 |
-
iface.launch()
|
|
|
|
| 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= "text-davinci-003",
|
| 20 |
prompt=f"{prompt}\n\nQ: {base_prompt}\nA:",
|
| 21 |
max_tokens=60,
|
| 22 |
n=1,
|
|
|
|
| 35 |
|
| 36 |
# Define the Gradio interface
|
| 37 |
prompt_input = Textbox("Enter a prompt", lines=3)
|
| 38 |
+
text_output = Label("")
|
| 39 |
image_output = Image()
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
iface = gr.Interface(
|
| 42 |
generate_image,
|
| 43 |
inputs=prompt_input,
|
|
|
|
| 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()
|