Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import gradio as gr
|
| 3 |
import replicate
|
| 4 |
import os
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# আপনার মডেল সেটআপ
|
| 8 |
MODEL_ID = "lucataco/flux-dev-lora"
|
|
@@ -10,46 +15,45 @@ LORA_URL = "https://huggingface.co/SahinaKhatun123/SahinaThumbnails/resolve/main
|
|
| 10 |
TRIGGER_WORD = "SahinaStyle"
|
| 11 |
|
| 12 |
def generate_image(prompt, aspect_ratio):
|
| 13 |
-
|
| 14 |
-
full_prompt = f"{prompt}, {TRIGGER_WORD}, youtube thumbnail, 4k quality, highly detailed"
|
|
|
|
|
|
|
| 15 |
|
| 16 |
try:
|
| 17 |
-
print(f"📡 Calling Replicate with prompt: {full_prompt}")
|
| 18 |
-
|
| 19 |
-
# Replicate কল করা হচ্ছে
|
| 20 |
output = replicate.run(
|
| 21 |
MODEL_ID,
|
| 22 |
input={
|
| 23 |
"hf_lora": LORA_URL,
|
| 24 |
-
"lora_scale":
|
| 25 |
"prompt": full_prompt,
|
| 26 |
"aspect_ratio": aspect_ratio,
|
| 27 |
"num_outputs": 1,
|
| 28 |
"output_format": "webp"
|
| 29 |
}
|
| 30 |
)
|
| 31 |
-
|
| 32 |
-
print(f"✅ Replicate Response: {output}") # রেজাল্ট আসলে এটা দেখাবে
|
| 33 |
-
return output[0], "Success! Image generated."
|
| 34 |
|
| 35 |
except Exception as e:
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
#
|
| 40 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 41 |
-
gr.Markdown("#
|
| 42 |
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column():
|
| 45 |
-
text_input = gr.Textbox(label="Video Title")
|
| 46 |
-
ratio = gr.Dropdown(["16:9", "1:1"], value="16:9", label="
|
| 47 |
-
gen_btn = gr.Button("Generate", variant="primary")
|
| 48 |
|
| 49 |
with gr.Column():
|
| 50 |
-
image_output = gr.Image(label="
|
| 51 |
-
|
| 52 |
|
| 53 |
-
gen_btn.click(fn=generate_image, inputs=[text_input, ratio], outputs=[image_output,
|
| 54 |
|
| 55 |
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import replicate
|
| 3 |
import os
|
| 4 |
+
|
| 5 |
+
# -------- সমস্যা সমাধানের কোড (FIX) --------
|
| 6 |
+
# আপনার টোকেন থেকে অদৃশ্য স্পেস বা এন্টার (\n) মুছে ফেলা হচ্ছে
|
| 7 |
+
if "REPLICATE_API_TOKEN" in os.environ:
|
| 8 |
+
raw_token = os.environ["REPLICATE_API_TOKEN"]
|
| 9 |
+
os.environ["REPLICATE_API_TOKEN"] = raw_token.strip()
|
| 10 |
+
# ----------------------------------------
|
| 11 |
|
| 12 |
# আপনার মডেল সেটআপ
|
| 13 |
MODEL_ID = "lucataco/flux-dev-lora"
|
|
|
|
| 15 |
TRIGGER_WORD = "SahinaStyle"
|
| 16 |
|
| 17 |
def generate_image(prompt, aspect_ratio):
|
| 18 |
+
# ট্রিগার ওয়ার্ড যুক্ত করা
|
| 19 |
+
full_prompt = f"{prompt}, {TRIGGER_WORD}, youtube thumbnail, 4k quality, highly detailed, vibrant colors"
|
| 20 |
+
|
| 21 |
+
print(f"🚀 Processing: {full_prompt}")
|
| 22 |
|
| 23 |
try:
|
|
|
|
|
|
|
|
|
|
| 24 |
output = replicate.run(
|
| 25 |
MODEL_ID,
|
| 26 |
input={
|
| 27 |
"hf_lora": LORA_URL,
|
| 28 |
+
"lora_scale": 1.2, # থাম্বনেইলের জন্য ১.২ পারফেক্ট ব্যালেন্স
|
| 29 |
"prompt": full_prompt,
|
| 30 |
"aspect_ratio": aspect_ratio,
|
| 31 |
"num_outputs": 1,
|
| 32 |
"output_format": "webp"
|
| 33 |
}
|
| 34 |
)
|
| 35 |
+
return output[0], "✅ Success! Thumbnail Generated."
|
|
|
|
|
|
|
| 36 |
|
| 37 |
except Exception as e:
|
| 38 |
+
error_msg = str(e)
|
| 39 |
+
if "nsfw" in error_msg.lower():
|
| 40 |
+
return None, "❌ Error: NSFW content detected. Try a different prompt."
|
| 41 |
+
return None, f"❌ Error: {error_msg}"
|
| 42 |
|
| 43 |
+
# অ্যাপের ডিজাইন
|
| 44 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 45 |
+
gr.Markdown("# 🎨 Sahina's Thumbnail Generator")
|
| 46 |
|
| 47 |
with gr.Row():
|
| 48 |
with gr.Column():
|
| 49 |
+
text_input = gr.Textbox(label="Video Title / Topic", placeholder="Ex: A shocked man looking at a flying car...")
|
| 50 |
+
ratio = gr.Dropdown(["16:9", "1:1", "9:16"], value="16:9", label="Size")
|
| 51 |
+
gen_btn = gr.Button("Generate Thumbnail ✨", variant="primary")
|
| 52 |
|
| 53 |
with gr.Column():
|
| 54 |
+
image_output = gr.Image(label="Generated Thumbnail")
|
| 55 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
| 56 |
|
| 57 |
+
gen_btn.click(fn=generate_image, inputs=[text_input, ratio], outputs=[image_output, status_output])
|
| 58 |
|
| 59 |
app.launch()
|