Tzetha commited on
Commit
1bd2025
·
1 Parent(s): 10f3c8b

Edited aoo

Browse files
Files changed (1) hide show
  1. app.py +68 -36
app.py CHANGED
@@ -1,38 +1,70 @@
1
  import streamlit as st
 
 
2
 
3
- # App Title
4
- st.title("Color color sa box")
5
-
6
- # Sliders for RGB values
7
- st.sidebar.header("Adjust Box Color")
8
- r = st.sidebar.slider("Red", 0, 255, 128, step=1)
9
- g = st.sidebar.slider("Green", 0, 255, 128, step=1)
10
- b = st.sidebar.slider("Blue", 0, 255, 128, step=1)
11
-
12
- # Slider for darkness/shade
13
- shade = st.sidebar.slider("Shade (0: Dark, 1: Light)", 0.0, 1.0, 0.5, step=0.01)
14
-
15
- # Calculate the adjusted RGB values based on shade
16
- adjusted_r = int(r * shade)
17
- adjusted_g = int(g * shade)
18
- adjusted_b = int(b * shade)
19
-
20
- # Display the box with adjusted color
21
- box_color = f"rgb({adjusted_r}, {adjusted_g}, {adjusted_b})"
22
- st.markdown(
23
- f"""
24
- <div style="
25
- width: 200px;
26
- height: 200px;
27
- background-color: {box_color};
28
- border: 1px solid black;">
29
- </div>
30
- """,
31
- unsafe_allow_html=True
32
- )
33
-
34
- # Show the current RGB values
35
- st.write("**Adjusted RGB Values:**")
36
- st.write(f"Red: {adjusted_r}, Green: {adjusted_g}, Blue: {adjusted_b}")
37
-
38
- st.write("Use the sliders in the sidebar to adjust the color, shade, and darkness of the box.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from PIL import Image, ImageDraw, ImageFont
3
+ import os
4
 
5
+ def add_text_to_image(image, top_text, bottom_text):
6
+ draw = ImageDraw.Draw(image)
7
+
8
+ # Load a font; change the path if not working or to use a custom font.
9
+ font_path = "arial.ttf"
10
+ font_size = int(image.width / 10) # Dynamic font size based on image width
11
+ try:
12
+ font = ImageFont.truetype(font_path, font_size)
13
+ except:
14
+ font = ImageFont.load_default()
15
+
16
+ # Helper function to calculate text size
17
+ def get_text_size(text, font):
18
+ bbox = draw.textbbox((0, 0), text, font=font)
19
+ return bbox[2] - bbox[0], bbox[3] - bbox[1]
20
+
21
+ # Top text
22
+ text_width, text_height = get_text_size(top_text, font)
23
+ top_text_position = ((image.width - text_width) // 2, 10)
24
+ draw.text(top_text_position, top_text, font=font, fill="white", stroke_fill="black", stroke_width=2)
25
+
26
+ # Bottom text
27
+ text_width, text_height = get_text_size(bottom_text, font)
28
+ bottom_text_position = ((image.width - text_width) // 2, image.height - text_height - 10)
29
+ draw.text(bottom_text_position, bottom_text, font=font, fill="white", stroke_fill="black", stroke_width=2)
30
+
31
+ return image
32
+
33
+
34
+ # Streamlit App Title
35
+ st.title("Meme Generator")
36
+
37
+ # File uploader for the image
38
+ uploaded_file = st.file_uploader("Upload an image for your meme:", type=["jpg", "jpeg", "png"])
39
+
40
+ if uploaded_file:
41
+ # Load the uploaded image
42
+ image = Image.open(uploaded_file)
43
+
44
+ # Get user input for captions
45
+ top_text = st.text_input("Top Text:", "")
46
+ bottom_text = st.text_input("Bottom Text:", "")
47
+
48
+ # Display the original image
49
+ st.image(image, caption="Original Image", use_column_width=True)
50
+
51
+ if st.button("Generate Meme"):
52
+ # Generate meme with captions
53
+ meme_image = add_text_to_image(image.copy(), top_text, bottom_text)
54
+
55
+ # Display the meme
56
+ st.image(meme_image, caption="Your Meme", use_column_width=True)
57
+
58
+ # Provide a download link
59
+ output_path = "meme.png"
60
+ meme_image.save(output_path)
61
+ with open(output_path, "rb") as file:
62
+ btn = st.download_button(
63
+ label="Download Meme",
64
+ data=file,
65
+ file_name="meme.png",
66
+ mime="image/png"
67
+ )
68
+
69
+ # Footer
70
+ st.write("WOW MEMES!!!")