Update app.py
#1
by
imparsa
- opened
app.py
CHANGED
|
@@ -1,25 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import random
|
| 4 |
-
import
|
| 5 |
import os
|
| 6 |
|
| 7 |
def process(Prompt):
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
with open(
|
| 16 |
-
|
| 17 |
f.write(response.content)
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
title = "Pollinations Image Generator"
|
| 22 |
description = "Pollinations API + Randomizer"
|
| 23 |
|
| 24 |
-
iface = gr.Interface(
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import random
|
| 4 |
+
import tempfile
|
| 5 |
import os
|
| 6 |
|
| 7 |
def process(Prompt):
|
| 8 |
+
# ایجاد یک فایل موقت
|
| 9 |
+
tmp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
| 10 |
+
tmp_file.close()
|
| 11 |
|
| 12 |
+
try:
|
| 13 |
+
response = requests.get(
|
| 14 |
+
f"https://image.pollinations.ai/prompt/{Prompt}?model=flux-realism&width=1024&height=1024&nologo=true&seed={random.randint(0,999999999)}"
|
| 15 |
+
)
|
| 16 |
+
response.raise_for_status()
|
| 17 |
+
with open(tmp_file.name, "wb") as f:
|
|
|
|
| 18 |
f.write(response.content)
|
| 19 |
+
return tmp_file.name
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"❌ خطا: {e}"
|
| 22 |
|
| 23 |
title = "Pollinations Image Generator"
|
| 24 |
description = "Pollinations API + Randomizer"
|
| 25 |
|
| 26 |
+
iface = gr.Interface(
|
| 27 |
+
fn=process,
|
| 28 |
+
inputs=gr.Textbox(lines=2, placeholder="اینجا متن خود را وارد کنید..."),
|
| 29 |
+
outputs="image",
|
| 30 |
+
title=title,
|
| 31 |
+
description=description
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
iface.launch()
|