zohaibterminator commited on
Commit
6d34127
·
verified ·
1 Parent(s): 1b10d27

updated En to Ur translation API

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -53,20 +53,19 @@ def translate(target, text):
53
  Returns:
54
  res (string): Translated text.
55
  '''
56
- url = "https://microsoft-translator-text.p.rapidapi.com/translate"
57
 
58
- querystring = {"api-version":"3.0","profanityAction":"NoAction","textType":"plain", "to":target}
59
-
60
- payload = [{ "Text": text }]
61
  headers = {
62
- "x-rapidapi-key": os.getenv("RAPIDAPI_LANG_TRANS"),
63
- "x-rapidapi-host": "microsoft-translator-text.p.rapidapi.com",
64
  "Content-Type": "application/json"
65
  }
66
 
67
- response = requests.post(url, json=payload, headers=headers, params=querystring)
68
  res = response.json()
69
- return res[0]["translations"][0]["text"]
 
70
 
71
 
72
  def infer(user_input: str):
 
53
  Returns:
54
  res (string): Translated text.
55
  '''
56
+ url = "https://google-api31.p.rapidapi.com/translate"
57
 
58
+ payload = { "text": text, "to": target, "from_lang": "" }
 
 
59
  headers = {
60
+ "x-rapidapi-key": "0875969c18mshea4b5d106303222p197cb2jsnd47e91b7da30",
61
+ "x-rapidapi-host": "google-api31.p.rapidapi.com",
62
  "Content-Type": "application/json"
63
  }
64
 
65
+ response = requests.post(url, json=payload, headers=headers)
66
  res = response.json()
67
+
68
+ return res[0]["translated"]
69
 
70
 
71
  def infer(user_input: str):