Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import base64
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Get API key from environment variable
|
| 7 |
api_key = os.environ.get("NVCF_API_KEY")
|
|
@@ -36,7 +38,6 @@ def generate_image(prompt, negative_prompt, sampler, seed, guidance_scale, infer
|
|
| 36 |
fetch_url = fetch_url_format + request_id
|
| 37 |
response = session.get(fetch_url, headers=headers)
|
| 38 |
|
| 39 |
-
|
| 40 |
response.raise_for_status()
|
| 41 |
response_body = response.json()
|
| 42 |
|
|
@@ -50,12 +51,11 @@ def generate_image(prompt, negative_prompt, sampler, seed, guidance_scale, infer
|
|
| 50 |
|
| 51 |
image_data = base64.b64decode(b64_image_data)
|
| 52 |
|
| 53 |
-
#
|
| 54 |
image = Image.open(BytesIO(image_data))
|
| 55 |
|
| 56 |
return image
|
| 57 |
|
| 58 |
-
|
| 59 |
# Create Gradio interface
|
| 60 |
iface = gr.Interface(
|
| 61 |
fn=generate_image,
|
|
@@ -71,4 +71,4 @@ iface = gr.Interface(
|
|
| 71 |
)
|
| 72 |
|
| 73 |
# Launch the Gradio app
|
| 74 |
-
iface.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
import base64
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
from PIL import Image # Corrected import
|
| 7 |
|
| 8 |
# Get API key from environment variable
|
| 9 |
api_key = os.environ.get("NVCF_API_KEY")
|
|
|
|
| 38 |
fetch_url = fetch_url_format + request_id
|
| 39 |
response = session.get(fetch_url, headers=headers)
|
| 40 |
|
|
|
|
| 41 |
response.raise_for_status()
|
| 42 |
response_body = response.json()
|
| 43 |
|
|
|
|
| 51 |
|
| 52 |
image_data = base64.b64decode(b64_image_data)
|
| 53 |
|
| 54 |
+
# Convert the binary data to a PIL Image
|
| 55 |
image = Image.open(BytesIO(image_data))
|
| 56 |
|
| 57 |
return image
|
| 58 |
|
|
|
|
| 59 |
# Create Gradio interface
|
| 60 |
iface = gr.Interface(
|
| 61 |
fn=generate_image,
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
# Launch the Gradio app
|
| 74 |
+
iface.launch()
|