Commit
·
614d206
1
Parent(s):
520f6d6
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,9 @@ import io
|
|
| 4 |
import random
|
| 5 |
import os
|
| 6 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
API_URL = "https://api-inference.huggingface.co/models/openskyml/open-diffusion-v1"
|
| 9 |
API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
|
|
@@ -48,7 +51,17 @@ def query(prompt, is_negative=False, image_style="None style", steps=8, cfg_scal
|
|
| 48 |
|
| 49 |
image_bytes = requests.post(API_URL, headers=headers, json=payload).content
|
| 50 |
image = Image.open(io.BytesIO(image_bytes))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
images.append(image)
|
|
|
|
| 52 |
return images
|
| 53 |
|
| 54 |
|
|
@@ -206,6 +219,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
-
text_button.click(query, inputs=[text_prompt, negative_prompt
|
| 210 |
|
| 211 |
demo.launch(show_api=False)
|
|
|
|
| 4 |
import random
|
| 5 |
import os
|
| 6 |
from PIL import Image
|
| 7 |
+
from huggingface_hub import HfApi
|
| 8 |
+
|
| 9 |
+
login(token=os.getenv("HF_READ_TOKEN"))
|
| 10 |
|
| 11 |
API_URL = "https://api-inference.huggingface.co/models/openskyml/open-diffusion-v1"
|
| 12 |
API_TOKEN = os.getenv("HF_READ_TOKEN") # it is free
|
|
|
|
| 51 |
|
| 52 |
image_bytes = requests.post(API_URL, headers=headers, json=payload).content
|
| 53 |
image = Image.open(io.BytesIO(image_bytes))
|
| 54 |
+
|
| 55 |
+
api = HfApi()
|
| 56 |
+
api.upload_file(
|
| 57 |
+
path_or_fileobj=image,
|
| 58 |
+
path_in_repo="images/img_"+random.randint(1, 2147483647)+".png",
|
| 59 |
+
repo_id="openskyml/prompts",
|
| 60 |
+
repo_type="dataset",
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
images.append(image)
|
| 64 |
+
)
|
| 65 |
return images
|
| 66 |
|
| 67 |
|
|
|
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
+
text_button.click(query, inputs=[text_prompt, negative_prompt], outputs=gallery_output)
|
| 223 |
|
| 224 |
demo.launch(show_api=False)
|