SahinaKhatun123 commited on
Commit
10be355
·
verified ·
1 Parent(s): 957cb08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -1,8 +1,13 @@
1
  import gradio as gr
2
- import gradio as gr
3
  import replicate
4
  import os
5
- import time
 
 
 
 
 
 
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
- print("🚀 Starting generation process...") # Logs-এ এটা ঁজবেন
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": 2.0,
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
- print(f"❌ ERROR HAPPENED: {str(e)}") # এরর হলে এটা দেখাবে
37
- return None, f"Error: {str(e)}"
 
 
38
 
39
- # UI ডিজাইন
40
  with gr.Blocks(theme=gr.themes.Soft()) as app:
41
- gr.Markdown("# 🎬 Debug Mode: Thumbnail Generator")
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="Ratio")
47
- gen_btn = gr.Button("Generate", variant="primary")
48
 
49
  with gr.Column():
50
- image_output = gr.Image(label="Result")
51
- status_box = gr.Textbox(label="Status Log")
52
 
53
- gen_btn.click(fn=generate_image, inputs=[text_input, ratio], outputs=[image_output, status_box])
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()