SrirakshaKR commited on
Commit
2919064
·
verified ·
1 Parent(s): 4efbd40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -36
app.py CHANGED
@@ -1,37 +1,3 @@
1
- import requests
2
- import io
3
- from PIL import Image
4
- import json
5
 
6
- API_URL = "https://api-inference.huggingface.co/models/ZB-Tech/Text-to-Image"
7
- headers = {"Authorization": "Bearer HF_API_KEY"}
8
-
9
- def query(payload):
10
- response = requests.post(API_URL, headers=headers, json=payload)
11
- if response.status_code == 200:
12
- content_type = response.headers.get("Content-Type", "")
13
- if "image" in content_type:
14
- return response.content # Returns raw image data
15
- else:
16
- # Log or print the unexpected content (likely JSON error message)
17
- print("Unexpected response format:", response.text)
18
- return None
19
- else:
20
- print("API Error:", response.status_code, response.text)
21
- return None
22
-
23
- # Request image data
24
- image_bytes = query({
25
- "inputs": "Astronaut riding a horse",
26
- })
27
-
28
- # Check if image_bytes contains valid data before proceeding
29
- if image_bytes:
30
- try:
31
- # Open image if it's valid
32
- image = Image.open(io.BytesIO(image_bytes))
33
- image.show() # Display the image (optional)
34
- except Exception as e:
35
- print("Error opening image:", e)
36
- else:
37
- print("Failed to retrieve image.")
 
1
+ import gradio as gr
 
 
 
2
 
3
+ gr.load("models/ZB-Tech/Text-to-Image").launch()