BounharAbdelaziz commited on
Commit
c26c590
·
verified ·
1 Parent(s): 541edf0

detect potential commercial missuse

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -79,7 +79,8 @@ def push_to_hf_dataset():
79
  "source_text": [item["source_text"] for item in translations_buffer],
80
  "translated_text": [item["translated_text"] for item in translations_buffer],
81
  "model_used": [item["model_used"] for item in translations_buffer],
82
- "timestamp": [item["timestamp"] for item in translations_buffer]
 
83
  })
84
 
85
  # Try to load existing dataset
@@ -135,7 +136,7 @@ def translate_ultra_supreme(text, model_name):
135
  translation = translator(text)[0]['translation_text']
136
  return translation
137
 
138
- def translate_text(text, model_choice):
139
  """ Main translation function """
140
  global translations_buffer, last_push_time
141
 
@@ -143,6 +144,11 @@ def translate_text(text, model_choice):
143
  if not text or text.strip() == "":
144
  return "Please enter text to translate."
145
 
 
 
 
 
 
146
  # Perform translation
147
  if model_choice in ["Terjman-Nano-v2", "Terjman-Large-v2"]:
148
  translation = translate_nano_large(text, model_choice)
@@ -156,7 +162,8 @@ def translate_text(text, model_choice):
156
  "source_text": text,
157
  "translated_text": translation,
158
  "model_used": model_choice,
159
- "timestamp": datetime.datetime.now().isoformat()
 
160
  })
161
 
162
  # Check if it's time to push to HF
@@ -183,13 +190,13 @@ def gradio_app():
183
  translate_button = gr.Button("Translate")
184
 
185
  # Link input and output
186
- def translate_and_update_status(text, model):
187
- translation = translate_text(text, model)
188
  return translation
189
 
190
  translate_button.click(
191
  fn=translate_and_update_status,
192
- inputs=[input_text, model_choice],
193
  outputs=[output_text]
194
  )
195
 
 
79
  "source_text": [item["source_text"] for item in translations_buffer],
80
  "translated_text": [item["translated_text"] for item in translations_buffer],
81
  "model_used": [item["model_used"] for item in translations_buffer],
82
+ "timestamp": [item["timestamp"] for item in translations_buffer],
83
+ "user_id": [item["user_id"] for item in translations_buffer] # Include user ID
84
  })
85
 
86
  # Try to load existing dataset
 
136
  translation = translator(text)[0]['translation_text']
137
  return translation
138
 
139
+ def translate_text(text, model_choice, request: gr.Request):
140
  """ Main translation function """
141
  global translations_buffer, last_push_time
142
 
 
144
  if not text or text.strip() == "":
145
  return "Please enter text to translate."
146
 
147
+ # Get the user ID (if logged in): to detect potential commercial missuse
148
+ user_id = "anonymous"
149
+ if request and hasattr(request, "username") and request.username:
150
+ user_id = request.username
151
+
152
  # Perform translation
153
  if model_choice in ["Terjman-Nano-v2", "Terjman-Large-v2"]:
154
  translation = translate_nano_large(text, model_choice)
 
162
  "source_text": text,
163
  "translated_text": translation,
164
  "model_used": model_choice,
165
+ "timestamp": datetime.datetime.now().isoformat(),
166
+ "user_id": user_id # Add the user ID to the dataset
167
  })
168
 
169
  # Check if it's time to push to HF
 
190
  translate_button = gr.Button("Translate")
191
 
192
  # Link input and output
193
+ def translate_and_update_status(text, model, request: gr.Request):
194
+ translation = translate_text(text, model, request)
195
  return translation
196
 
197
  translate_button.click(
198
  fn=translate_and_update_status,
199
+ inputs=[input_text, model_choice, gr.Request()],
200
  outputs=[output_text]
201
  )
202