Update app.py
Browse files
app.py
CHANGED
@@ -7,11 +7,13 @@ from dotenv import load_dotenv
|
|
7 |
# Load environment variables
|
8 |
load_dotenv()
|
9 |
|
10 |
-
# Configuration
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
12 |
REDDIT_API = "https://www.reddit.com/r/trending/top.json?limit=5"
|
13 |
DEFAULT_TRENDS = ["Celebrity gossip", "Tech news", "Movie drama", "Gaming leaks"]
|
14 |
STYLES = ["Realistic", "Cartoon", "Anime", "3D Render"]
|
|
|
|
|
15 |
|
16 |
# Initialize clients
|
17 |
client = InferenceClient(token=HF_TOKEN)
|
@@ -25,16 +27,19 @@ def get_trends():
|
|
25 |
return DEFAULT_TRENDS
|
26 |
|
27 |
def generate_meme(prompt: str, style: str):
|
28 |
-
"""Generate meme using
|
29 |
try:
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
)
|
34 |
|
|
|
35 |
image = client.text_to_image(
|
36 |
-
model=
|
37 |
-
prompt=enhanced_prompt,
|
38 |
negative_prompt="low quality, text, watermark",
|
39 |
height=512,
|
40 |
width=512
|
@@ -48,16 +53,16 @@ def generate_meme(prompt: str, style: str):
|
|
48 |
with gr.Blocks(title="π Viral Meme Generator", css="static/style.css") as demo:
|
49 |
gr.Markdown("# <center>π₯ Create Viral Memes in Seconds</center>")
|
50 |
|
51 |
-
with gr.Row():
|
52 |
with gr.Column(scale=3):
|
53 |
-
gr.HTML('<img src="file/static/assets/logo.png" style="height: 200px">')
|
54 |
trend_select = gr.Dropdown(get_trends(), label="Trending Topics")
|
55 |
style_select = gr.Dropdown(STYLES, label="Visual Style", value="Realistic")
|
56 |
text_input = gr.Textbox(label="Your Message", placeholder="Add funny text...")
|
57 |
generate_btn = gr.Button("Generate Now", variant="primary")
|
58 |
|
59 |
with gr.Column(scale=2):
|
60 |
-
output_img = gr.Image(label="Your Meme", height=512, width=512)
|
61 |
gr.HTML("""
|
62 |
<div class="monetization">
|
63 |
<script type='text/javascript' src='https://storage.ko-fi.com/cdn/widget/Widget_2.js'></script>
|
|
|
7 |
# Load environment variables
|
8 |
load_dotenv()
|
9 |
|
10 |
+
# Configuration - Changed to SDXL for image generation
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
12 |
REDDIT_API = "https://www.reddit.com/r/trending/top.json?limit=5"
|
13 |
DEFAULT_TRENDS = ["Celebrity gossip", "Tech news", "Movie drama", "Gaming leaks"]
|
14 |
STYLES = ["Realistic", "Cartoon", "Anime", "3D Render"]
|
15 |
+
IMAGE_MODEL = "stabilityai/stable-diffusion-xl-base-1.0" # Verified working model
|
16 |
+
TEXT_MODEL = "deepseek-ai/Janus-Pro-7B" # For text processing
|
17 |
|
18 |
# Initialize clients
|
19 |
client = InferenceClient(token=HF_TOKEN)
|
|
|
27 |
return DEFAULT_TRENDS
|
28 |
|
29 |
def generate_meme(prompt: str, style: str):
|
30 |
+
"""Generate meme using SDXL for images and Janus-Pro for text refinement"""
|
31 |
try:
|
32 |
+
# First enhance text with Janus-Pro
|
33 |
+
enhanced_prompt = client.text_generation(
|
34 |
+
model=TEXT_MODEL,
|
35 |
+
prompt=f"Improve this meme caption about {prompt} in {style} style:",
|
36 |
+
max_new_tokens=100
|
37 |
)
|
38 |
|
39 |
+
# Generate image with SDXL
|
40 |
image = client.text_to_image(
|
41 |
+
model=IMAGE_MODEL,
|
42 |
+
prompt=f"Trending meme template ({style} style): {enhanced_prompt}",
|
43 |
negative_prompt="low quality, text, watermark",
|
44 |
height=512,
|
45 |
width=512
|
|
|
53 |
with gr.Blocks(title="π Viral Meme Generator", css="static/style.css") as demo:
|
54 |
gr.Markdown("# <center>π₯ Create Viral Memes in Seconds</center>")
|
55 |
|
56 |
+
with gr.Row():
|
57 |
with gr.Column(scale=3):
|
58 |
+
gr.HTML('<img src="file/static/assets/logo.png" style="height: 200px">')
|
59 |
trend_select = gr.Dropdown(get_trends(), label="Trending Topics")
|
60 |
style_select = gr.Dropdown(STYLES, label="Visual Style", value="Realistic")
|
61 |
text_input = gr.Textbox(label="Your Message", placeholder="Add funny text...")
|
62 |
generate_btn = gr.Button("Generate Now", variant="primary")
|
63 |
|
64 |
with gr.Column(scale=2):
|
65 |
+
output_img = gr.Image(label="Your Meme", height=512, width=512)
|
66 |
gr.HTML("""
|
67 |
<div class="monetization">
|
68 |
<script type='text/javascript' src='https://storage.ko-fi.com/cdn/widget/Widget_2.js'></script>
|