dschandra commited on
Commit
7153980
·
verified ·
1 Parent(s): 48348dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -18,7 +18,10 @@ def generate_comic(prompt):
18
  return f"Error: {response.status_code}, {response.text}"
19
 
20
  # Extracting generated images
21
- images = response.json()["generated_images"]
 
 
 
22
 
23
  # Convert image bytes into PIL Image format
24
  pil_images = [Image.open(io.BytesIO(img)) for img in images]
@@ -33,15 +36,15 @@ def gradio_interface():
33
 
34
  with gr.Row():
35
  prompt = gr.Textbox(label="Enter your short story description", placeholder="Once upon a time...")
36
-
37
- # Directly setting grid and height in Gallery constructor
38
- output_gallery = gr.Gallery(label="Generated Comic Panels", elem_id="gallery", columns=3).style(height="300px")
39
-
40
  submit_button = gr.Button("Generate Comic")
41
-
42
  # Set up button functionality
43
  submit_button.click(fn=generate_comic, inputs=prompt, outputs=output_gallery)
44
-
45
  return demo
46
 
47
  # Run the Gradio app
 
18
  return f"Error: {response.status_code}, {response.text}"
19
 
20
  # Extracting generated images
21
+ images = response.json().get("generated_images", [])
22
+
23
+ if not images:
24
+ return "No images were generated, please try again with a different prompt."
25
 
26
  # Convert image bytes into PIL Image format
27
  pil_images = [Image.open(io.BytesIO(img)) for img in images]
 
36
 
37
  with gr.Row():
38
  prompt = gr.Textbox(label="Enter your short story description", placeholder="Once upon a time...")
39
+
40
+ # Directly specifying the number of columns without .style()
41
+ output_gallery = gr.Gallery(label="Generated Comic Panels", columns=3, height=300)
42
+
43
  submit_button = gr.Button("Generate Comic")
44
+
45
  # Set up button functionality
46
  submit_button.click(fn=generate_comic, inputs=prompt, outputs=output_gallery)
47
+
48
  return demo
49
 
50
  # Run the Gradio app