main
t 10 months ago
parent c829a8c2fd
commit bfb92fe337

@ -0,0 +1,41 @@
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

@ -0,0 +1,38 @@
import telebot
### LOAD TOKEN ###
import json, os
if not os.path.exists('db.json'):
db = {"token": "None"}
js = json.dumps(db, indent=2)
with open("db.json", "w") as outfile:
outfile.write(js)
print('Input token in "None" (db.json)')
exit()
with open('db.json', 'r') as openfile:
db = json.load(openfile)
API_TOKEN = db["token"]
bot = telebot.TeleBot(API_TOKEN)
##################
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(message, "None")
### MAIN ###
from api import *
@bot.message_handler(func=lambda message: True)
def echo_message(message):
bot.send_chat_action(message.chat.id, "typing", 30)
bot.reply_to(message, gen(message.text, message.chat.id))
############
bot.infinity_polling()
Loading…
Cancel
Save