ztjona commited on
Commit
44db148
·
1 Parent(s): 66fa7b0

FASTER! Change to inference API in app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -1,21 +1,35 @@
 
 
1
  import gradio as gr
2
- from diffusers import DiffusionPipeline
3
- # model = "runwayml/stable-diffusion-v1-5"
4
- model = "ztjona/scopic-diffusion-OW-v1.4.1"
5
- generator = DiffusionPipeline.from_pretrained(model)
6
- prompt = "portrait photo of a old warrior chief"
 
 
 
7
 
8
 
9
  def infer(prompt):
10
- return generator(prompt).images[0]
 
 
11
 
 
12
 
13
 
14
  demo = gr.Interface(
15
  fn=infer,
16
  inputs="text",
17
  outputs="image",
18
- examples=[["city and clouds"]],
 
 
 
 
 
 
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