Update main.py
Browse files
main.py
CHANGED
@@ -9,9 +9,25 @@ import string
|
|
9 |
import time
|
10 |
from queue import Queue
|
11 |
from threading import Thread
|
|
|
|
|
|
|
12 |
|
13 |
app = FastAPI()
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
text_gen = gr.Interface.load("models/Gustavosta/MagicPrompt-Stable-Diffusion")
|
16 |
proc1 = gr.Interface.load("models/playgroundai/playground-v2-1024px-aesthetic")
|
17 |
|
@@ -89,7 +105,9 @@ def generate_prompts(prompt_text: str):
|
|
89 |
|
90 |
@app.get("/send_inputs")
|
91 |
def send_inputs(inputs: str, noise_level: float):
|
92 |
-
|
|
|
|
|
93 |
|
94 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
95 |
|
|
|
9 |
import time
|
10 |
from queue import Queue
|
11 |
from threading import Thread
|
12 |
+
import requests
|
13 |
+
import io
|
14 |
+
from PIL import Image
|
15 |
|
16 |
app = FastAPI()
|
17 |
|
18 |
+
API_URL = "https://api-inference.huggingface.co/models/playgroundai/playground-v2-1024px-aesthetic"
|
19 |
+
API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
|
20 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
21 |
+
def generate_image(prompt):
|
22 |
+
payload = {"inputs": prompt}
|
23 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
24 |
+
image_bytes = response.content
|
25 |
+
image = Image.open(io.BytesIO(image_bytes))
|
26 |
+
return image
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
|
31 |
text_gen = gr.Interface.load("models/Gustavosta/MagicPrompt-Stable-Diffusion")
|
32 |
proc1 = gr.Interface.load("models/playgroundai/playground-v2-1024px-aesthetic")
|
33 |
|
|
|
105 |
|
106 |
@app.get("/send_inputs")
|
107 |
def send_inputs(inputs: str, noise_level: float):
|
108 |
+
generated_image = generate_image(inputs)
|
109 |
+
return generated_image
|
110 |
+
|
111 |
|
112 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
113 |
|