toecm commited on
Commit
d142667
·
verified ·
1 Parent(s): 2a93cac

Update src/ux_agent.py

Browse files
Files changed (1) hide show
  1. src/ux_agent.py +36 -0
src/ux_agent.py CHANGED
@@ -152,6 +152,30 @@ class AgentUX:
152
  except: pass
153
  return json.dumps({"clarification": text})
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  # ==========================================
156
  # SOCIOLINGUISTIC PIPELINE
157
  # ==========================================
@@ -1143,6 +1167,18 @@ class AgentUX:
1143
  outputs=[feedback_msg, btn_over, alert_player],
1144
  api_name="check_and_submit_logic"
1145
  )
 
 
 
 
 
 
 
 
 
 
 
 
1146
  # ⬆️ END OF API BRIDGE ⬆️
1147
 
1148
  return ui
 
152
  except: pass
153
  return json.dumps({"clarification": text})
154
 
155
+ def api_translate_peer(self, text, source_dialect, target_dialect):
156
+ """Translates an utterance directly from one dialect to another."""
157
+ if not text: return ""
158
+
159
+ prompt = f"""
160
+ Translate the following utterance from {source_dialect} to {target_dialect}.
161
+ Utterance: "{text}"
162
+
163
+ CRITICAL INSTRUCTIONS:
164
+ 1. Output ONLY the translated text. No conversational filler.
165
+ 2. Preserve the cultural pragmatics and emotional tone.
166
+ 3. Do not explain the translation, just provide the direct equivalent in {target_dialect}.
167
+ """
168
+ try:
169
+ if hasattr(self.brain, 'gemini_manager') and self.brain.gemini_manager:
170
+ response = self.brain.gemini_manager.client.models.generate_content(
171
+ model='gemini-2.0-flash',
172
+ contents=prompt
173
+ )
174
+ return response.text.replace("```json", "").replace("```", "").replace('"', '').strip()
175
+ except Exception as e:
176
+ print(f"Peer Translation Error: {e}")
177
+ return text # Fallback to original text if API fails
178
+
179
  # ==========================================
180
  # SOCIOLINGUISTIC PIPELINE
181
  # ==========================================
 
1167
  outputs=[feedback_msg, btn_over, alert_player],
1168
  api_name="check_and_submit_logic"
1169
  )
1170
+ # 🟢 NEW: Peer-to-Peer Translation Endpoint
1171
+ api_btn_translate = gr.Button()
1172
+ api_translate_text_in = gr.Textbox()
1173
+ api_translate_source_in = gr.Textbox()
1174
+ api_translate_target_in = gr.Textbox()
1175
+ api_translate_out = gr.Textbox()
1176
+ api_btn_translate.click(
1177
+ fn=self.api_translate_peer,
1178
+ inputs=[api_translate_text_in, api_translate_source_in, api_translate_target_in],
1179
+ outputs=[api_translate_out],
1180
+ api_name="translate_peer"
1181
+ )
1182
  # ⬆️ END OF API BRIDGE ⬆️
1183
 
1184
  return ui