wuhp commited on
Commit
c34e9fd
Β·
verified Β·
1 Parent(s): 1721cb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -13,7 +13,7 @@ def load_prompts(file_path="prompts.json"):
13
  except Exception as e:
14
  print(f"⚠️ Could not load prompts.json: {e}")
15
  return {
16
- "base_system": "You are a bilingual translator fluent in AAVE and English.",
17
  "styles": {},
18
  "direction_prompts": {},
19
  "platform_notes": {}
@@ -56,7 +56,7 @@ def build_system_instruction(direction: str, style: str) -> str:
56
  return system_instruction
57
 
58
  def gemini_translate(client, text: str, direction: str, style: str):
59
- """Translate between AAVE and Standard English using prompts.json + platform notes."""
60
  system_instruction = build_system_instruction(direction, style)
61
  direction_prompt = PROMPTS.get("direction_prompts", {}).get(direction, "")
62
 
@@ -112,24 +112,31 @@ def translate(api_key, text, image, direction, style):
112
  result = f"❌ Error: {e}"
113
  return result
114
 
 
 
 
115
  with gr.Blocks(theme=gr.themes.Soft(), title="Ebonics ⇄ English Translator") as demo:
116
  gr.Markdown("# Ebonics ⇄ Standard English Translator")
117
 
118
  with gr.Row():
119
  with gr.Column(scale=1):
120
- api_key = gr.Textbox(label="πŸ”‘ Gemini API Key", type="password", placeholder="Enter your Gemini API key here")
 
 
 
 
121
 
122
  direction = gr.Radio(
123
- ["AAVE ➜ English", "English ➜ AAVE"],
124
  label="Translation Direction",
125
- value="AAVE ➜ English"
126
  )
127
 
128
  style = gr.Dropdown(
129
  label="Translation Style",
130
- choices=["Tweet to Professional", "Casual Digital", "Academic Analysis"],
131
- value="Casual Digital",
132
- info="Choose translation tone or style (changes with direction)."
133
  )
134
 
135
  text_input = gr.Textbox(
@@ -145,10 +152,17 @@ with gr.Blocks(theme=gr.themes.Soft(), title="Ebonics ⇄ English Translator") a
145
  output_box = gr.Textbox(label="Translated Output", lines=8)
146
 
147
  def update_styles(direction):
148
- if direction == "AAVE ➜ English":
149
- return gr.update(choices=["Tweet to Professional", "Casual Digital", "Academic Analysis", "Media Caption"], value="Casual Digital")
 
 
 
 
150
  else:
151
- return gr.update(choices=["Twitter/XTalk", "IG Caption Vibe", "Thread Talk", "Comment Section", "Chill Tweet", "Voice Note Energy"], value="Twitter/XTalk")
 
 
 
152
 
153
  direction.change(update_styles, inputs=[direction], outputs=[style])
154
 
 
13
  except Exception as e:
14
  print(f"⚠️ Could not load prompts.json: {e}")
15
  return {
16
+ "base_system": "You are a bilingual translator fluent in Ebonics and English.",
17
  "styles": {},
18
  "direction_prompts": {},
19
  "platform_notes": {}
 
56
  return system_instruction
57
 
58
  def gemini_translate(client, text: str, direction: str, style: str):
59
+ """Translate between Ebonics and Standard English using prompts.json + platform notes."""
60
  system_instruction = build_system_instruction(direction, style)
61
  direction_prompt = PROMPTS.get("direction_prompts", {}).get(direction, "")
62
 
 
112
  result = f"❌ Error: {e}"
113
  return result
114
 
115
+
116
+ # ==== GRADIO UI ====
117
+
118
  with gr.Blocks(theme=gr.themes.Soft(), title="Ebonics ⇄ English Translator") as demo:
119
  gr.Markdown("# Ebonics ⇄ Standard English Translator")
120
 
121
  with gr.Row():
122
  with gr.Column(scale=1):
123
+ api_key = gr.Textbox(
124
+ label="πŸ”‘ Gemini API Key",
125
+ type="password",
126
+ placeholder="Enter your Gemini API key here"
127
+ )
128
 
129
  direction = gr.Radio(
130
+ ["Ebonics ➜ English", "English ➜ Ebonics"],
131
  label="Translation Direction",
132
+ value="Ebonics ➜ English"
133
  )
134
 
135
  style = gr.Dropdown(
136
  label="Translation Style",
137
+ choices=["Formal", "Casual", "Academic", "Default"],
138
+ value="Casual",
139
+ info="Choose a translation tone or style (changes with direction)."
140
  )
141
 
142
  text_input = gr.Textbox(
 
152
  output_box = gr.Textbox(label="Translated Output", lines=8)
153
 
154
  def update_styles(direction):
155
+ """Update style options dynamically based on direction."""
156
+ if direction == "Ebonics ➜ English":
157
+ return gr.update(
158
+ choices=["Formal", "Casual", "Academic", "Default"],
159
+ value="Casual"
160
+ )
161
  else:
162
+ return gr.update(
163
+ choices=["Modern", "Classic", "Chill", "Energetic", "Default"],
164
+ value="Modern"
165
+ )
166
 
167
  direction.change(update_styles, inputs=[direction], outputs=[style])
168