Spaces:
Runtime error
Runtime error
FASTER! Change to inference API in app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,35 @@
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def infer(prompt):
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
demo = gr.Interface(
|
| 15 |
fn=infer,
|
| 16 |
inputs="text",
|
| 17 |
outputs="image",
|
| 18 |
-
examples=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
title="Generate images based on artist Oswaldo Guayasamín",
|
| 20 |
description="Write a prompt and an image will be generated. ",
|
| 21 |
article="""Fune tuned Stable Diffusion model. \n
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
from os import getenv
|
| 3 |
import gradio as gr
|
| 4 |
+
import requests
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
API_URL = (
|
| 8 |
+
"https://api-inference.huggingface.co/models/ztjona/scopic-diffusion-OW-v1.4.1"
|
| 9 |
+
)
|
| 10 |
+
API_TOKEN = getenv("API_TOKEN")
|
| 11 |
+
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
| 12 |
|
| 13 |
|
| 14 |
def infer(prompt):
|
| 15 |
+
payload = {"inputs": prompt}
|
| 16 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 17 |
+
image_bytes = response.content
|
| 18 |
|
| 19 |
+
return Image.open(io.BytesIO(image_bytes))
|
| 20 |
|
| 21 |
|
| 22 |
demo = gr.Interface(
|
| 23 |
fn=infer,
|
| 24 |
inputs="text",
|
| 25 |
outputs="image",
|
| 26 |
+
examples=[
|
| 27 |
+
["city and clouds"],
|
| 28 |
+
["tea party"],
|
| 29 |
+
["mother working"],
|
| 30 |
+
["buddhist monk"],
|
| 31 |
+
["governor of old town"],
|
| 32 |
+
],
|
| 33 |
title="Generate images based on artist Oswaldo Guayasamín",
|
| 34 |
description="Write a prompt and an image will be generated. ",
|
| 35 |
article="""Fune tuned Stable Diffusion model. \n
|