Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,25 @@
|
|
| 1 |
import os
|
| 2 |
import asyncio
|
| 3 |
|
| 4 |
-
import prodiapy
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
# Load API key from Hugging Face Secrets
|
| 8 |
-
api_key = os.getenv("PRODIA_AI_API")
|
| 9 |
-
prodia = prodiapy.Prodia(api_key=api_key)
|
| 10 |
|
| 11 |
async def generate_image(prompt):
|
| 12 |
-
job = await prodia.sd.
|
| 13 |
-
result = await prodia.
|
| 14 |
return result.image_url
|
| 15 |
|
| 16 |
-
async def process_image(prompt):
|
| 17 |
-
return await asyncio.to_thread(generate_image, prompt) # Run in a thread
|
| 18 |
-
|
| 19 |
demo = gr.Interface(
|
| 20 |
-
fn=
|
| 21 |
inputs="text",
|
| 22 |
outputs="image",
|
| 23 |
title="Async Prodia Image Generation",
|
| 24 |
description="Generate images asynchronously using Prodia API.",
|
| 25 |
)
|
| 26 |
|
| 27 |
-
demo.queue()
|
| 28 |
-
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import asyncio
|
| 3 |
|
| 4 |
+
import prodiapy.aio # Import the async module
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
# Load API key from Hugging Face Secrets
|
| 8 |
+
api_key = os.getenv("PRODIA_AI_API")
|
| 9 |
+
prodia = prodiapy.aio.Prodia(api_key=api_key) # Initialize async client
|
| 10 |
|
| 11 |
async def generate_image(prompt):
|
| 12 |
+
job = await prodia.sd.generate(prompt=prompt)
|
| 13 |
+
result = await prodia.wait(job)
|
| 14 |
return result.image_url
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
demo = gr.Interface(
|
| 17 |
+
fn=generate_image,
|
| 18 |
inputs="text",
|
| 19 |
outputs="image",
|
| 20 |
title="Async Prodia Image Generation",
|
| 21 |
description="Generate images asynchronously using Prodia API.",
|
| 22 |
)
|
| 23 |
|
| 24 |
+
demo.queue()
|
| 25 |
+
demo.launch()
|