aahmed10202 commited on
Commit
5467807
·
verified ·
1 Parent(s): 5466ddc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -29
app.py CHANGED
@@ -1,35 +1,26 @@
1
- import torch
2
  import streamlit as st
3
- from diffusers import StableDiffusionPipeline
4
-
5
- # Check if CUDA (GPU) is available, otherwise use CPU
6
- device = "cuda" if torch.cuda.is_available() else "cpu"
7
 
8
- # Load the pre-trained Stable Diffusion model and move it to the correct device
9
- pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
10
- pipe.to(device)
11
 
12
- # Title and description
13
- st.markdown('<div class="title">🔥 Memeify - Text-to-Meme Generator 🔥</div>', unsafe_allow_html=True)
14
- st.markdown('<div class="description">Enter a description, and the AI will generate a meme image for you!</div>', unsafe_allow_html=True)
15
 
16
- # User input for meme description
17
- input_text = st.text_input("Enter meme description:", key="input", placeholder="e.g., dog dancing")
18
 
19
- # Generate meme image when button is clicked
20
- if st.button("Generate Meme", key="generate", help="Click to generate a meme from your description"):
21
- if input_text:
22
- try:
23
- # Modify the input prompt for meme generation
24
- modified_prompt = "MEME of an Image of " + input_text
25
-
26
- # Generate the image from the modified prompt
27
- image = pipe(modified_prompt).images[0]
28
-
29
- # Display the generated image in the Streamlit app
30
- st.image(image, caption=f"Meme: {input_text}", use_column_width=True)
31
 
32
- except Exception as e:
33
- st.error(f"An error occurred while generating the meme: {e}")
34
- else:
35
- st.warning("Please enter a description to generate a meme.")
 
 
1
  import streamlit as st
2
+ import torch
3
+ from diffusers import DiffusionPipeline
4
+ from PIL import Image
 
5
 
6
+ # Load the pre-trained model and LoRA weights
7
+ pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev")
8
+ pipe.load_lora_weights("prithivMLmods/Flux-Meme-Xd-LoRA")
9
 
10
+ # Streamlit app
11
+ st.title("Memeify")
 
12
 
13
+ # Input field for the meme prompt
14
+ prompt = st.text_area("Enter your meme prompt:", "meme, A medium-sized painting of a white T-rex in the middle of a dark, stormy night. The t-rex is facing towards the left side of the frame, its head turned towards the right. Its mouth is open, revealing its sharp teeth. A rooster is standing in the foreground of the painting, with a red cap on its head. The roosters head is turned to the right, and the word \"Remember who you are\" is written in white text above it. The background is a deep blue, with dark gray clouds and a crescent moon in the upper left corner of the image. There are mountains in the background, and a few other animals can be seen in the lower right corner.")
15
 
16
+ # Button to generate the meme
17
+ if st.button("Generate Meme"):
18
+ with st.spinner("Generating meme..."):
19
+ # Generate the image using the provided prompt
20
+ image = pipe(prompt).images[0]
21
+
22
+ # Convert the image to PIL format
23
+ pil_image = Image.fromarray(image.astype('uint8'))
 
 
 
 
24
 
25
+ # Display the generated image
26
+ st.image(pil_image, caption="Generated Meme", use_column_width=True)