Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import random
|
| 4 |
+
import sys
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
def download(url):
|
| 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(url)
|
| 13 |
+
|
| 14 |
+
if response.status_code == 200:
|
| 15 |
+
|
| 16 |
+
with open(file_path, "wb") as f:
|
| 17 |
+
|
| 18 |
+
f.write(response.content)
|
| 19 |
+
|
| 20 |
+
return(file_path)
|
| 21 |
+
|
| 22 |
+
def process(prompt):
|
| 23 |
+
download_file("https://image.pollinations.ai/prompt/" + text + ('.' * random.randint(0, 100)))
|
| 24 |
+
|
| 25 |
+
iface = gr.Interface(fn=process, inputs="text", outputs="image")
|
| 26 |
+
iface.launch()
|