Spaces:
Runtime error
Runtime error
Commit
·
da277b2
1
Parent(s):
2893bcd
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,36 @@
|
|
| 1 |
-
import openai
|
| 2 |
import gradio
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
openai.api_key = openai.api_key
|
| 6 |
|
| 7 |
-
# Load the text-to-image generation model
|
| 8 |
model_path = "models/dreamlike-art/dreamlike-photoreal-2.0"
|
| 9 |
model_prefix = "photoreal style"
|
| 10 |
-
model = gradio.
|
| 11 |
|
| 12 |
-
# Define a function to generate text response using OpenAI API
|
| 13 |
def generate_text(prompt):
|
| 14 |
response = openai.Completion.create(
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
)
|
| 22 |
-
return response.choices[0].text
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
prompt = text + ", in " + model_prefix
|
| 27 |
image_return = model(prompt)
|
| 28 |
return image_return
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
outputs
|
| 35 |
-
"image", gradio.outputs.Image(label="Generated Image", type="numpy"),
|
| 36 |
-
"text", gradio.outputs.Textbox(label="Generated Text")
|
| 37 |
-
],
|
| 38 |
-
title="AlStable Text-to-Image",
|
| 39 |
-
description="Generates an image from a text prompt and provides text response.",
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
# Add a callback function to update the "Generated Text" output box based on the input text
|
| 43 |
-
def update_output_text(inp):
|
| 44 |
-
response_text = generate_text(inp)
|
| 45 |
-
interface.set_output_text(response_text)
|
| 46 |
-
|
| 47 |
-
# Set the callback function for the input textbox
|
| 48 |
-
interface.inputs[0].set_property("on_input", update_output_text)
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
interface.launch()
|
|
|
|
|
|
|
| 1 |
import gradio
|
| 2 |
+
import openai
|
| 3 |
|
| 4 |
+
openai.api_key = "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"
|
|
|
|
| 5 |
|
|
|
|
| 6 |
model_path = "models/dreamlike-art/dreamlike-photoreal-2.0"
|
| 7 |
model_prefix = "photoreal style"
|
| 8 |
+
model = gradio.load_model(model_path)
|
| 9 |
|
|
|
|
| 10 |
def generate_text(prompt):
|
| 11 |
response = openai.Completion.create(
|
| 12 |
+
engine="davinci",
|
| 13 |
+
prompt=prompt,
|
| 14 |
+
max_tokens=1024,
|
| 15 |
+
n=1,
|
| 16 |
+
stop=None,
|
| 17 |
+
temperature=0.7,
|
| 18 |
)
|
| 19 |
+
return response.choices[0].text
|
| 20 |
|
| 21 |
+
def process_prompt(prompt):
|
| 22 |
+
prompt += ", in " + model_prefix
|
|
|
|
| 23 |
image_return = model(prompt)
|
| 24 |
return image_return
|
| 25 |
|
| 26 |
+
def update_output_text(prompt):
|
| 27 |
+
text = generate_text(prompt)
|
| 28 |
+
interface.outputs[0].set_text(text)
|
| 29 |
+
output_image = process_prompt(text)
|
| 30 |
+
interface.outputs[1].set_image(output_image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
interface = gradio.Interface(fn=update_output_text,
|
| 33 |
+
inputs=[gradio.inputs.Textbox(label="Enter Prompt:")],
|
| 34 |
+
outputs=[gradio.outputs.Textbox(label="Generated Text"), gradio.outputs.Image(label="Generated Image")],
|
| 35 |
+
title='AlStable Text to Image')
|
| 36 |
interface.launch()
|