Upload 5 files
Browse files- app.py +74 -0
- requirements.txt +4 -0
- static/assets/logo.png +0 -0
- static/assets/watermark.png +0 -0
- static/style.css +24 -0
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import gradio as gr
|
4 |
+
from huggingface_hub import InferenceClient
|
5 |
+
from dotenv import load_dotenv
|
6 |
+
|
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)
|
18 |
+
|
19 |
+
def get_trends():
|
20 |
+
"""Fetch trending topics with Reddit API fallback"""
|
21 |
+
try:
|
22 |
+
res = requests.get(REDDIT_API, headers={"User-Agent": "MemeBot/1.0"}, timeout=3)
|
23 |
+
return [post["data"]["title"] for post in res.json()["data"]["children"]]
|
24 |
+
except:
|
25 |
+
return DEFAULT_TRENDS
|
26 |
+
|
27 |
+
def generate_meme(prompt: str, style: str):
|
28 |
+
"""Generate meme using DeepSeek Janus-Pro"""
|
29 |
+
try:
|
30 |
+
enhanced_prompt = (
|
31 |
+
f"Trending meme template ({style} style): {prompt}. "
|
32 |
+
"Viral social media format, high contrast, funny text overlay"
|
33 |
+
)
|
34 |
+
|
35 |
+
image = client.text_to_image(
|
36 |
+
model="deepseek-ai/janus-pro",
|
37 |
+
prompt=enhanced_prompt,
|
38 |
+
negative_prompt="low quality, text, watermark",
|
39 |
+
height=512,
|
40 |
+
width=512
|
41 |
+
)
|
42 |
+
return image
|
43 |
+
except Exception as e:
|
44 |
+
print(f"Generation error: {e}")
|
45 |
+
return None
|
46 |
+
|
47 |
+
# Build UI
|
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(variant="panel"):
|
52 |
+
with gr.Column(scale=3):
|
53 |
+
gr.HTML('<img src="file/static/assets/logo.png" width="200">')
|
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", shape=(512, 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>
|
64 |
+
<script type='text/javascript'>kofiwidget2.init('Support Us', '#FF5F5F', 'rooblecali');kofiwidget2.draw();</script>
|
65 |
+
</div>
|
66 |
+
""")
|
67 |
+
download_btn = gr.Button("🔒 Unlock HD Download ($0.99)")
|
68 |
+
|
69 |
+
# Event handling
|
70 |
+
generate_btn.click(fn=generate_meme, inputs=[text_input, style_select], outputs=output_img)
|
71 |
+
trend_select.change(fn=lambda x: x, inputs=trend_select, outputs=text_input)
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
demo.launch(server_port=int(os.getenv("PORT", 7860)))
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.12.0
|
2 |
+
huggingface_hub==0.20.2
|
3 |
+
requests==2.31.0
|
4 |
+
python-dotenv==1.0.0
|
static/assets/logo.png
ADDED
![]() |
static/assets/watermark.png
ADDED
![]() |
static/style.css
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
|
3 |
+
color: white !important;
|
4 |
+
}
|
5 |
+
|
6 |
+
button#generate-btn {
|
7 |
+
background: #ff4757 !important;
|
8 |
+
border: none !important;
|
9 |
+
padding: 15px 30px !important;
|
10 |
+
font-size: 1.2em !important;
|
11 |
+
border-radius: 25px !important;
|
12 |
+
transition: transform 0.3s !important;
|
13 |
+
}
|
14 |
+
|
15 |
+
button#generate-btn:hover {
|
16 |
+
transform: scale(1.05) !important;
|
17 |
+
}
|
18 |
+
|
19 |
+
.monetization {
|
20 |
+
margin-top: 20px;
|
21 |
+
padding: 15px;
|
22 |
+
background: rgba(255, 255, 255, 0.1);
|
23 |
+
border-radius: 10px;
|
24 |
+
}
|