Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,28 @@
|
|
| 1 |
-
import
|
| 2 |
-
import gradio as gr
|
| 3 |
import asyncio
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
return result.image_url
|
| 10 |
|
| 11 |
-
def
|
| 12 |
-
return asyncio.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
demo
|
| 15 |
-
demo.launch()
|
|
|
|
| 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.async_generate(prompt=prompt)
|
| 13 |
+
result = await prodia.async_wait(job)
|
| 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=process_image,
|
| 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() # Enable queuing to handle multiple requests
|
| 28 |
+
demo.launch()
|