aahmed10202 commited on
Commit
01602dc
Β·
verified Β·
1 Parent(s): c5f0c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -29
app.py CHANGED
@@ -1,43 +1,25 @@
1
- from diffusers import StableDiffusionPipeline
2
  import torch
3
  import streamlit as st
 
4
 
5
- # Set the page config as the very first command
6
- st.set_page_config(page_title="πŸ”₯ Memeify - Text-to-Meme Generator πŸ”₯", page_icon="πŸ”₯", layout="wide")
7
-
8
- # Load the model
9
- model_id = "CompVis/stable-diffusion-v1-4"
10
- device = "cuda"
11
-
12
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
13
- pipe = pipe.to(device)
14
-
15
- # Custom styling for the page
16
- st.markdown("""
17
- </style>
18
- """, unsafe_allow_html=True)
19
 
20
  # Title and description
21
- st.markdown('<div class="title">πŸ”₯ MemeForge - Text-to-Meme Generator πŸ”₯</div>', unsafe_allow_html=True)
22
  st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
23
 
24
  # User input for meme description
25
- input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., A funny dog looking confused.")
26
 
27
  # Generate meme image when button is clicked
28
  if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
29
  if input_text:
30
  modified_prompt = "MEME of an Image of " + input_text
31
-
32
- # Show a loading spinner while the image is being generated
33
- with st.spinner('Generating your meme...'):
34
- # Generate image from the prompt
35
- image = pipe(modified_prompt, num_inference_steps=10).images[0]
36
-
37
- # Display the generated image
38
- st.image(image, caption="Your Generated Meme", use_column_width=True)
39
-
40
- # Save the image
41
- image.save("generated_meme.png")
42
  else:
43
- st.warning("Please enter a description to generate a meme.")
 
 
1
  import torch
2
  import streamlit as st
3
+ from diffusers import DiffusionPipeline
4
 
5
+ # Load the pre-trained Stable Diffusion model
6
+ pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Title and description
9
+ st.markdown('<div class="title">πŸ”₯ Memeify - Text-to-Meme Generator πŸ”₯</div>', unsafe_allow_html=True)
10
  st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
11
 
12
  # User input for meme description
13
+ input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., dog dancing")
14
 
15
  # Generate meme image when button is clicked
16
  if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
17
  if input_text:
18
  modified_prompt = "MEME of an Image of " + input_text
19
+ # Generate the image from the modified prompt
20
+ image = pipe(modified_prompt).images[0]
21
+
22
+ # Display the generated image in the Streamlit app
23
+ st.image(image, caption=f"Meme: {input_text}", use_column_width=True)
 
 
 
 
 
 
24
  else:
25
+ st.warning("Please enter a description to generate a meme.")