bh4vay commited on
Commit
005fdf4
·
verified ·
1 Parent(s): 12a97e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import torch
3
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
4
  from diffusers import StableDiffusionPipeline
5
- from PIL import Image, ImageDraw, ImageFont
6
 
7
  # Check for GPU availability
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -64,25 +64,25 @@ def generate_story(prompt):
64
  return "Error generating story."
65
 
66
  # Function to add a speech bubble to an image
67
- def add_speech_bubble(image, text, position=(50, 50)):
68
- draw = ImageDraw.Draw(image)
69
 
70
- try:
71
- font = ImageFont.truetype("arial.ttf", 20)
72
- except IOError:
73
- font = ImageFont.load_default()
74
 
75
- text_bbox = draw.textbbox((0, 0), text, font=font)
76
- text_width = text_bbox[2] - text_bbox[0]
77
- text_height = text_bbox[3] - text_bbox[1]
78
 
79
- bubble_width, bubble_height = text_width + 30, text_height + 20
80
- bubble_x, bubble_y = position
81
 
82
- draw.ellipse([bubble_x, bubble_y, bubble_x + bubble_width, bubble_y + bubble_height], fill="white", outline="black")
83
- draw.text((bubble_x + 15, bubble_y + 10), text, font=font, fill="black")
84
 
85
- return image
86
 
87
  # Streamlit UI
88
  st.title("🦸‍♂️ AI Comic Story Generator")
@@ -109,8 +109,8 @@ if user_prompt:
109
 
110
  # Extract first sentence (50 characters max) for speech bubble
111
  speech_text = generated_story.split(".")[0][:50]
112
- image_with_bubble = add_speech_bubble(image, speech_text, position=(50, 50))
113
 
114
- st.image(image_with_bubble, caption="Generated Comic Image", use_container_width=True)
115
  except Exception as e:
116
  st.error(f"❌ Error generating image: {e}")
 
2
  import torch
3
  from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
4
  from diffusers import StableDiffusionPipeline
5
+ from PIL import Image
6
 
7
  # Check for GPU availability
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
64
  return "Error generating story."
65
 
66
  # Function to add a speech bubble to an image
67
+ # def add_speech_bubble(image, text, position=(50, 50)):
68
+ # draw = ImageDraw.Draw(image)
69
 
70
+ # try:
71
+ # font = ImageFont.truetype("arial.ttf", 20)
72
+ # except IOError:
73
+ # font = ImageFont.load_default()
74
 
75
+ # text_bbox = draw.textbbox((0, 0), text, font=font)
76
+ # text_width = text_bbox[2] - text_bbox[0]
77
+ # text_height = text_bbox[3] - text_bbox[1]
78
 
79
+ # bubble_width, bubble_height = text_width + 30, text_height + 20
80
+ # bubble_x, bubble_y = position
81
 
82
+ # draw.ellipse([bubble_x, bubble_y, bubble_x + bubble_width, bubble_y + bubble_height], fill="white", outline="black")
83
+ # draw.text((bubble_x + 15, bubble_y + 10), text, font=font, fill="black")
84
 
85
+ # return image
86
 
87
  # Streamlit UI
88
  st.title("🦸‍♂️ AI Comic Story Generator")
 
109
 
110
  # Extract first sentence (50 characters max) for speech bubble
111
  speech_text = generated_story.split(".")[0][:50]
112
+ # image_with_bubble = add_speech_bubble(image, speech_text, position=(50, 50))
113
 
114
+ st.image(image, caption="Generated Comic Image", use_container_width=True)
115
  except Exception as e:
116
  st.error(f"❌ Error generating image: {e}")