Spaces:
Running
Running
Ryouko65777
commited on
Commit
•
0867019
1
Parent(s):
8881861
Update app.py
Browse files
app.py
CHANGED
@@ -11,17 +11,23 @@ API_TOKEN = os.getenv("HF_API_TOKEN") # Ensure you've set this environment vari
|
|
11 |
API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
|
12 |
|
13 |
# Function to call Hugging Face API and get the generated image
|
14 |
-
def generate_image(prompt):
|
15 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
16 |
data = {"inputs": prompt}
|
17 |
|
|
|
|
|
|
|
18 |
response = requests.post(API_URL, headers=headers, json=data)
|
19 |
|
20 |
if response.status_code == 200:
|
|
|
21 |
image_bytes = BytesIO(response.content)
|
22 |
image = Image.open(image_bytes)
|
|
|
23 |
return image
|
24 |
else:
|
|
|
25 |
return f"Error: {response.status_code}, {response.text}"
|
26 |
|
27 |
# Create Gradio interface
|
@@ -35,8 +41,8 @@ def create_ui():
|
|
35 |
with gr.Row():
|
36 |
output_image = gr.Image(label="Generated Image")
|
37 |
|
38 |
-
# Link the button to the function
|
39 |
-
generate_button.click(fn=generate_image, inputs=prompt_input, outputs=output_image)
|
40 |
|
41 |
return ui
|
42 |
|
|
|
11 |
API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
|
12 |
|
13 |
# Function to call Hugging Face API and get the generated image
|
14 |
+
def generate_image(prompt, progress=gr.Progress()):
|
15 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
16 |
data = {"inputs": prompt}
|
17 |
|
18 |
+
# Initialize progress
|
19 |
+
progress(0, desc="Starting image generation...")
|
20 |
+
|
21 |
response = requests.post(API_URL, headers=headers, json=data)
|
22 |
|
23 |
if response.status_code == 200:
|
24 |
+
progress(50, desc="Processing image...")
|
25 |
image_bytes = BytesIO(response.content)
|
26 |
image = Image.open(image_bytes)
|
27 |
+
progress(100, desc="Completed")
|
28 |
return image
|
29 |
else:
|
30 |
+
progress(100, desc="Error occurred")
|
31 |
return f"Error: {response.status_code}, {response.text}"
|
32 |
|
33 |
# Create Gradio interface
|
|
|
41 |
with gr.Row():
|
42 |
output_image = gr.Image(label="Generated Image")
|
43 |
|
44 |
+
# Link the button to the function with progress
|
45 |
+
generate_button.click(fn=generate_image, inputs=prompt_input, outputs=output_image, show_progress=True)
|
46 |
|
47 |
return ui
|
48 |
|