Spaces:
Sleeping
Sleeping
changes
Browse files- app.py +18 -12
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,19 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
variant="fp16")
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
# Define the inference function
|
14 |
def generate_image(prompt):
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Create the Gradio interface
|
19 |
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image", live=True)
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
|
5 |
+
api_key = os.getenv("HF_API_KEY")
|
6 |
+
# Define the Hugging Face API endpoint and your API key
|
7 |
+
api_url = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
|
8 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
|
|
9 |
|
10 |
+
# Define the inference function using the Hugging Face API
|
|
|
|
|
11 |
def generate_image(prompt):
|
12 |
+
payload = {
|
13 |
+
"inputs": prompt
|
14 |
+
}
|
15 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
16 |
+
|
17 |
+
if response.status_code == 200:
|
18 |
+
# If the response is successful, return the image
|
19 |
+
image = response.content
|
20 |
+
return image
|
21 |
+
else:
|
22 |
+
return "Error: " + response.text
|
23 |
|
24 |
# Create the Gradio interface
|
25 |
iface = gr.Interface(fn=generate_image, inputs="text", outputs="image", live=True)
|
requirements.txt
CHANGED
@@ -1,3 +1,5 @@
|
|
1 |
diffusers
|
2 |
torch
|
3 |
gradio
|
|
|
|
|
|
1 |
diffusers
|
2 |
torch
|
3 |
gradio
|
4 |
+
accelerate
|
5 |
+
python-dotenv
|