File size: 878 Bytes
d83c996
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

import requests
import os

def translate_text(text_string, source_lang, target_lang):

    api_key=os.getenv("SARVAM_API_KEY", "")
    url = "https://api.sarvam.ai/translate"
    payload = {
        "input": text_string,
        "source_language_code": source_lang,
        "target_language_code": target_lang,
        "speaker_gender": "Male",
        "mode": "formal",
        "model": "mayura:v1",
        "enable_preprocessing": True
    }
    headers = {"Content-Type": "application/json",
            'API-Subscription-Key': f"{api_key}"
            }

    response = requests.request("POST", url, json=payload, headers=headers)

    #print(response.text)
    return response.text


#text_string = "Who is the founder of Bengaluru?"
#source_lang = "en-IN"
#target_lang = "kn-IN"
#response_text = translate_text(text_string, source_lang, target_lang)
#print(response_text)