radinhas commited on
Commit
bcc577e
1 Parent(s): c671a86

Update apis/chat_api.py

Browse files
Files changed (1) hide show
  1. apis/chat_api.py +6 -31
apis/chat_api.py CHANGED
@@ -162,7 +162,7 @@ class ChatAPIApp:
162
  MODEL_MAP = {
163
  "t5-base": "t5-base",
164
  "t5-small": "t5-small",
165
- "t5-large": "t5-3b",
166
  "t5-3b": "t5-3b",
167
  "mbart-large-50-many-to-many-mmt": "facebook/mbart-large-50-many-to-many-mmt",
168
  "nllb-200-distilled-600M": "facebook/nllb-200-distilled-600M",
@@ -173,37 +173,12 @@ class ChatAPIApp:
173
  target_model = item.model
174
  else:
175
  target_model = "default"
176
-
177
- model_fullname = MODEL_MAP[target_model]
178
- request_url = (
179
- f"https://api-inference.huggingface.co/models/{model_fullname}"
180
- )
181
- request_headers = {
182
- "Content-Type": "application/json",
183
- }
184
- request_body = {
185
- "inputs": item.input_text,
186
- "parameters": {
187
- "src_lang": item.from_language,
188
- "tgt_lang": item.to_language
189
- }
190
- }
191
- enver.set_envs(proxies=True)
192
- stream = requests.post(
193
- request_url,
194
- headers=request_headers,
195
- json=request_body,
196
- proxies=enver.requests_proxies,
197
- stream=False,
198
- )
199
- status_code = stream.status_code
200
- if status_code == 200:
201
- result = stream.json()
202
- else:
203
- result = stream.text
204
-
205
  item_response = {
206
- "statue": status_code,
207
  "result": result,
208
  }
209
  json_compatible_item_data = jsonable_encoder(item_response)
 
162
  MODEL_MAP = {
163
  "t5-base": "t5-base",
164
  "t5-small": "t5-small",
165
+ "t5-large": "t5-large",
166
  "t5-3b": "t5-3b",
167
  "mbart-large-50-many-to-many-mmt": "facebook/mbart-large-50-many-to-many-mmt",
168
  "nllb-200-distilled-600M": "facebook/nllb-200-distilled-600M",
 
173
  target_model = item.model
174
  else:
175
  target_model = "default"
176
+
177
+ translator = pipeline("translation_"+item.from_language+"_to_"+item.to_language, model=target_model)
178
+ result = translator(item.input_text)
179
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  item_response = {
181
+ "statue": 200,
182
  "result": result,
183
  }
184
  json_compatible_item_data = jsonable_encoder(item_response)