Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -1,25 +1,34 @@
1
  import gradio as gr
2
  import requests
3
  import random
4
- import sys
5
  import os
6
 
7
  def process(Prompt):
8
- filename = str(random.randint(111111111, 999999999)) + ".png"
 
 
9
 
10
- file_path = os.path.join(os.path.dirname(__file__), filename)
11
-
12
- response = requests.get("https://image.pollinations.ai/prompt/" + Prompt + "?model=flux-realism&width=2048&height=2048&nologo=true&seed=" + str(random.randint(0, 999999999)))
13
- if response.status_code == 200:
14
-
15
- with open(file_path, "wb") as f:
16
-
17
  f.write(response.content)
18
-
19
- return(file_path)
 
20
 
21
  title = "Pollinations Image Generator"
22
  description = "Pollinations API + Randomizer"
23
 
24
- iface = gr.Interface(fn=process, inputs="text", outputs="image", title=title, description=description)
25
- iface.launch()
 
 
 
 
 
 
 
 
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()