You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
919 B

from gradio_client import Client
#client = Client("https://skier8402-mistral-super-fast.hf.space/")
from deep_translator import GoogleTranslator
def predict(prompt, client):
global iddb
result = client.predict(
prompt,
0.5, # 'Temperature'
256, # 'Max new tokens'
0.9, # 'Top-p (nucleus sampling)'
1.2, # 'Repetition penalty'
api_name="/chat"
)
return result
# text IN language IN
def translate(text, source):
if source == "ru":
target = "en"
elif source == "en":
target = "ru"
out = GoogleTranslator(source = source, target = target).translate(text)
return out
iddb = {}
def gen(text, id):
global iddb
if str(id) not in iddb:
client = Client("https://skier8402-mistral-super-fast.hf.space/")
iddb[str(id)] = client
else:
client = iddb[str(id)]
prompt = translate(text, "ru")
predicted = translate( predict(prompt, client), "en" ).replace("</s>", "")
return predicted