Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,34 @@
|
|
| 1 |
-
import requests, json, random, string
|
| 2 |
from fastapi import FastAPI, Query
|
| 3 |
-
from fastapi.responses import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def session_hash():
|
| 11 |
-
return ''.join(random.choices(string.ascii_lowercase + string.digits, k=12))
|
| 12 |
|
| 13 |
|
| 14 |
@app.get("/api/generate/prompt")
|
| 15 |
def generate(prompt: str = Query(...)):
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
50,
|
| 26 |
-
True
|
| 27 |
-
],
|
| 28 |
-
"event_data": None,
|
| 29 |
-
"fn_index": 1,
|
| 30 |
-
"trigger_id": 6,
|
| 31 |
-
"session_hash": sh
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
requests.post(
|
| 35 |
-
f"{BASE_URL}/queue/join?__theme=dark",
|
| 36 |
-
json=payload,
|
| 37 |
-
headers={"Content-Type": "application/json"}
|
| 38 |
)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
url = f"{BASE_URL}/queue/data?session_hash={sh}"
|
| 42 |
-
with requests.get(url, stream=True) as r:
|
| 43 |
-
for line in r.iter_lines():
|
| 44 |
-
if line:
|
| 45 |
-
yield line + b"\n"
|
| 46 |
|
| 47 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Query
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
from gradio_client import Client
|
| 4 |
+
import base64
|
| 5 |
+
import requests
|
| 6 |
+
import tempfile
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
+
client = Client("Qwen/Qwen-Image")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
@app.get("/api/generate/prompt")
|
| 15 |
def generate(prompt: str = Query(...)):
|
| 16 |
+
result = client.predict(
|
| 17 |
+
prompt=prompt,
|
| 18 |
+
seed=0,
|
| 19 |
+
randomize_seed=True,
|
| 20 |
+
aspect_ratio="16:9",
|
| 21 |
+
guidance_scale=4,
|
| 22 |
+
num_inference_steps=50,
|
| 23 |
+
prompt_enhance=True,
|
| 24 |
+
api_name="/infer"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
+
img = result[0] # dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
return {
|
| 30 |
+
"prompt": prompt,
|
| 31 |
+
"image_url": img.get("url"),
|
| 32 |
+
"size": img.get("size"),
|
| 33 |
+
"mime_type": img.get("mime_type")
|
| 34 |
+
}
|