Arpit1234 commited on
Commit
3a478bb
·
verified ·
1 Parent(s): 478dad5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import gradio as gr
3
+ import io
4
+ from PIL import Image
5
+ import hashlib
6
+
7
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
8
+ headers = {"Authorization": ""}
9
+
10
+ def query(payload):
11
+ response = requests.post(API_URL, headers=headers, json=payload)
12
+ return response.content
13
+
14
+ def generate_image(prompt):
15
+ # Add a unique identifier to the prompt
16
+ prompt_with_identifier = prompt + str(hashlib.md5(prompt.encode()).hexdigest())
17
+ image_bytes = query({
18
+ "inputs": prompt_with_identifier,
19
+ })
20
+ image = Image.open(io.BytesIO(image_bytes))
21
+ return image
22
+
23
+ iface = gr.Interface(generate_image,
24
+ inputs="text",
25
+ outputs="image",
26
+ title="Generate Image from Text",
27
+ description="Enter a text prompt to generate a new image each time.",
28
+ allow_flagging=False)
29
+
30
+ iface.launch()