takumi0002 commited on
Commit
7b3b0be
·
verified ·
1 Parent(s): 8326d73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -2,6 +2,32 @@ import os
2
  import requests
3
  import gradio as gr
4
  import re
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Registry for Key Status
7
  key_status_registry = {}
@@ -27,7 +53,8 @@ class AIService:
27
  keys = AIService.get_all_keys(prefix)
28
  label = engine.split(" ")[-1]
29
  status_label = "ស្ថានភាព/Status"
30
- html = f"<div style='display: flex; gap: 8px; align-items: center; margin-bottom: 10px;'><b style='color: #94a3b8; font-size: 12px;'>{label} {status_label}:</b>"
 
31
 
32
  if not keys:
33
  html += "<span style='color: #ef4444; font-size: 10px;'>រកមិនឃើញ Key</span>"
@@ -40,7 +67,6 @@ class AIService:
40
 
41
  @staticmethod
42
  def call_api(engine, prompt):
43
- # បង្កើន Temperature បន្តិច ដើម្បីឱ្យចុចម្ដងទៀត វាផ្លាស់ប្តូរពាក្យថ្មីល្អជាងមុន
44
  temp = 0.85
45
  if "Gemini" in engine:
46
  keys = AIService.get_all_keys("GEMINI_API_KEY")
@@ -88,7 +114,6 @@ def translator_hub(text, target_lang, engine):
88
  if not text.strip(): return "", AIService.get_status_html(engine)
89
  lang_name = re.sub(r'[^\w\s]', '', target_lang).strip()
90
 
91
- # សម្រួល Instruction ឱ្យយល់ពីបរិបទដែលមេចង់បាន (Slang, Emotion, Pronouns, Swear words)
92
  instruction = f"""Translate the content into {lang_name} naturally.
93
  STRICT RULES:
94
  1. OUTPUT ONLY the translated text. NO explanations or notes.
@@ -107,10 +132,17 @@ STRICT RULES:
107
  return re.sub(r'```[a-zA-Z]*\n?|```', '', result).strip(), AIService.get_status_html(engine)
108
  return "❌ Error: API Key ឬ Model មិនដំណើរការ", AIService.get_status_html(engine)
109
 
110
- custom_css = "body { background: #0f172a !important; } .btn-trans { background: #10b981 !important; color: white !important; } .btn-clear { background: #475569 !important; color: white !important; }"
 
 
 
 
 
 
 
111
 
112
- with gr.Blocks(title="SRT Pro (Triple Model)") as demo:
113
- gr.Markdown("<h1 style='text-align: center; color: #60a5fa;'>🎬 SMART TRANSLATOR PRO</h1>")
114
  with gr.Row():
115
  with gr.Column():
116
  lang_opt = gr.Dropdown(["🇰🇭 Khmer", "🇺🇸 English", "🇨🇳 Chinese", "🇹🇭 Thai"], value="🇰🇭 Khmer", label="Language")
@@ -127,8 +159,9 @@ with gr.Blocks(title="SRT Pro (Triple Model)") as demo:
127
  # Events
128
  engine_opt.change(AIService.get_status_html, inputs=[engine_opt], outputs=[status_ui])
129
  btn_trans.click(translator_hub, [input_box, lang_opt, engine_opt], [output_box, status_ui])
130
- btn_copy.click(None, output_box, js="(v) => { navigator.clipboard.writeText(v); alert('✅ ចម្លងរួចរាល់!'); }")
131
  btn_clear.click(lambda: ("", ""), None, [input_box, output_box])
132
 
133
  if __name__ == "__main__":
 
134
  demo.launch(server_name="0.0.0.0", server_port=7860, css=custom_css, ssr_mode=False)
 
2
  import requests
3
  import gradio as gr
4
  import re
5
+ from datetime import datetime
6
+
7
+ # === ១. បន្ថែម Logic សម្រាប់ប្តូររូបរាង (Theme) តាមរដូវកាល ===
8
+ def get_seasonal_config():
9
+ month = datetime.now().month
10
+ # រដូវរងា (វិច្ឆិកា, ធ្នូ, មករា) - ពណ៌ខៀវត្រជាក់
11
+ if month in [11, 12, 1]:
12
+ return {
13
+ "bg": "#0f172a", "accent": "#38bdf8", "btn": "#0369a1",
14
+ "title": "❄️ WINTER FROST EDITION"
15
+ }
16
+ # រដូវក្ដៅ (មីនា, មេសា, ឧសភា) - ពណ៌មាស/ទឹកក្រូច
17
+ elif month in [3, 4, 5]:
18
+ return {
19
+ "bg": "#1c1917", "accent": "#fbbf24", "btn": "#b45309",
20
+ "title": "☀️ SUMMER BLAZE EDITION"
21
+ }
22
+ # រដូវភ្លៀង/ស្លឹកឈើជ្រុះ (ផ្សេងៗ) - ពណ៌បៃតងស្រស់
23
+ else:
24
+ return {
25
+ "bg": "#064e3b", "accent": "#10b981", "btn": "#047857",
26
+ "title": "🌿 RAINY FOREST EDITION"
27
+ }
28
+
29
+ # ទាញយកការកំណត់ពណ៌តាមខែបច្ចុប្បន្ន
30
+ s_theme = get_seasonal_config()
31
 
32
  # Registry for Key Status
33
  key_status_registry = {}
 
53
  keys = AIService.get_all_keys(prefix)
54
  label = engine.split(" ")[-1]
55
  status_label = "ស្ថានភាព/Status"
56
+ # ប្រើពណ៌ accent តាមរដូវកាលសម្រាប់ Label
57
+ html = f"<div style='display: flex; gap: 8px; align-items: center; margin-bottom: 10px;'><b style='color: {s_theme['accent']}; font-size: 12px;'>{label} {status_label}:</b>"
58
 
59
  if not keys:
60
  html += "<span style='color: #ef4444; font-size: 10px;'>រកមិនឃើញ Key</span>"
 
67
 
68
  @staticmethod
69
  def call_api(engine, prompt):
 
70
  temp = 0.85
71
  if "Gemini" in engine:
72
  keys = AIService.get_all_keys("GEMINI_API_KEY")
 
114
  if not text.strip(): return "", AIService.get_status_html(engine)
115
  lang_name = re.sub(r'[^\w\s]', '', target_lang).strip()
116
 
 
117
  instruction = f"""Translate the content into {lang_name} naturally.
118
  STRICT RULES:
119
  1. OUTPUT ONLY the translated text. NO explanations or notes.
 
132
  return re.sub(r'```[a-zA-Z]*\n?|```', '', result).strip(), AIService.get_status_html(engine)
133
  return "❌ Error: API Key ឬ Model មិនដំណើរការ", AIService.get_status_html(engine)
134
 
135
+ # === . កែសម្រួល CSS ឱ្យដើរតាម Dynamic Theme ===
136
+ custom_css = f"""
137
+ body, .gradio-container {{ background-color: {s_theme['bg']} !important; color: white !important; }}
138
+ .btn-trans {{ background-color: {s_theme['btn']} !important; color: white !important; border: 1px solid {s_theme['accent']} !important; }}
139
+ .btn-clear {{ background-color: #475569 !important; color: white !important; }}
140
+ h1 {{ color: {s_theme['accent']} !important; text-shadow: 0 0 10px {s_theme['accent']}55; }}
141
+ .fieldset, .input-label {{ color: {s_theme['accent']} !important; }}
142
+ """
143
 
144
+ with gr.Blocks(title=f"SRT Pro - {s_theme['title']}", css=custom_css) as demo:
145
+ gr.Markdown(f"<h1 style='text-align: center;'>🎬 {s_theme['title']}</h1>")
146
  with gr.Row():
147
  with gr.Column():
148
  lang_opt = gr.Dropdown(["🇰🇭 Khmer", "🇺🇸 English", "🇨🇳 Chinese", "🇹🇭 Thai"], value="🇰🇭 Khmer", label="Language")
 
159
  # Events
160
  engine_opt.change(AIService.get_status_html, inputs=[engine_opt], outputs=[status_ui])
161
  btn_trans.click(translator_hub, [input_box, lang_opt, engine_opt], [output_box, status_ui])
162
+ btn_copy.click(None, output_box, js="(v) => {{ navigator.clipboard.writeText(v); alert('✅ ចម្លងរួចរាល់!'); }}")
163
  btn_clear.click(lambda: ("", ""), None, [input_box, output_box])
164
 
165
  if __name__ == "__main__":
166
+ # Launch កម្មវិធី
167
  demo.launch(server_name="0.0.0.0", server_port=7860, css=custom_css, ssr_mode=False)