def batcher(params, batch): import tensorflow as tf import tensorflow_hub as hub import re import seaborn as sns import matplotlib.pyplot as plt import numpy as np import os from yandex.Translater import Translater tr = Translater() tr.set_key( 'trnsl.1.1.20190129T181632Z.6ad260c3f03e55a5.ae512973f3fa9c42fec01e4218fb4efd03a61a1b' ) # Api key found on https://translate.yandex.com/developers/keys tr.set_from_lang('ru') tr.set_to_lang('en') module_url = "https://tfhub.dev/google/universal-sentence-encoder/2" embed = hub.Module(module_url) l = len(batch) for i in range(l): tr.set_text(batch[i]) sentence = tr.translate() batch[i] = sentence messages = batch with tf.Session() as session: session.run( [tf.global_variables_initializer(), tf.tables_initializer()]) message_embeddings = session.run(embed(messages)) embeddings = format(message_embeddings) return embeddings
def __init__(self,to_lang='es',from_lang='en'): token = "TOKEN" #get here https://translate.yandex.com/developers/keys tr = Translater() tr.set_key(token) tr.set_to_lang(to_lang) tr.set_from_lang(from_lang) self.from_lang_default = from_lang self.tr = tr
def init(update, context): bot = context.bot var_messagge = update.message.text[6:] # Variables currenttimestr = 'Tempo attuale a ' citynotfoundstr = 'Non ho trovato la città' tempunit = 'celsius' tempstr = 'C°' lang = 'it' # Code try: tr = Translater() tr.set_key(Config.YANDEX_API) tr.set_from_lang('en') tr.set_to_lang(lang) weather = pyowm.OWM(Config.OPENWEATHER_API).weather_at_place( var_messagge.lower().capitalize()).get_weather() status = weather.get_status() desc = weather.get_detailed_status() for a, b in weather.get_temperature(unit=tempunit).items(): if a == 'temp': temp = b if a == 'temp_min': mintemp = b if a == 'temp_max': maxtemp = b def sendweathermsg(icon): msgtext = currenttimestr + var_messagge.lower().capitalize( ) + ':\n\n' if icon == '': msgtext = msgtext + desc.capitalize() else: msgtext = msgtext + icon + ' ' + desc.capitalize() + ' ' + icon msgtext = msgtext + '\nHumidity: ' + str(weather.get_humidity( )) + '%\nTemp: ' + str(temp) + tempstr + ', Min Temp: ' + str( mintemp) + tempstr + ', Max Temp: ' + str(maxtemp) + tempstr tr.set_text(msgtext) bot.send_message(update.message.chat_id, text=tr.translate(), parse_mode='HTML') if status == 'Clouds': sendweathermsg('☁️') elif status == 'Clear': sendweathermsg('☀️') elif status == 'Rain': sendweathermsg('🌧') elif status == 'Drizzle': sendweathermsg('🌧') elif status == 'Mist': sendweathermsg('🌫') else: sendweathermsg('') except: bot.send_message(update.message.chat_id, text=citynotfoundstr, parse_mode='HTML')
def translate(): tr = Translater() tr.set_key('Insert_your_API_Key_Here') # Api key found on https://translate.yandex.com/developers/keys text_to_translate = 'شركة ذات مسؤولية محدودة' tr.set_text(text_to_translate) tr.set_from_lang('ar') tr.set_to_lang('en') translated_txt = tr.translate() print(translated_txt)
def translater(self): ru_str = self.ru_str tr = Translater() tr.set_key(self.token) tr.set_from_lang("ru") tr.set_to_lang("en") tr.set_text(ru_str) en_str = tr.translate() self.result = en_str print("Перевод:", self.result)
def traduceCarTec(cadenaEntrada): apiTranslateEplan = """trnsl.1.1.20190308T091207Z.xxx""" tr = Translater() tr.set_key(apiTranslateEplan) tr.set_from_lang('es') tr.set_to_lang('en') f.write("===> TraduceCarTec: " + str(cadenaEntrada) + str(type(cadenaEntrada))) tr.set_text(cadenaEntrada) cadEng = tr.translate() return (cadEng)
class Translate: def __init__(self): self.tin = Translater() self.tin.set_key("#your yandex id here") def translate(self, text, target): try: self.tin.set_to_lang(target) self.tin.set_text(text) self.tin.set_from_lang(self.tin.detect_lang()) self.r = self.tin.translate() return self.r except: print("Translate Failed.")
def init(update, context): bot = context.bot message_var = update.message.text[8:] try: tr = Translater() tr.set_key( Config.YANDEX_API ) # Api key found on https://translate.yandex.com/developers/keys tr.set_text(message_var) tr.set_from_lang('it') tr.set_to_lang('en') bot.send_message(update.message.chat_id, tr.translate()) except: bot.send_message(update.message.chat_id, text="Perfavore inserisci una frase.")
def translate(self, text, lanFrom, lanTo): if self.times != 0: tr = Translater() tr.set_key(secretKey) if re.search(r'[А-я]', text): tr.set_from_lang('ru') tr.set_to_lang('en') else: tr.set_from_lang('en') tr.set_to_lang('ru') if text != "": tr.set_text(text) textboxR.delete('1.0', "end-1c") textboxR.insert("1.0", tr.translate()) self.times += 1
def traductionChained(utt, languages): tr = Translater() tr.set_key( 'trnsl.1.1.20200203T095917Z.30bf7af5cf091999.513bc5df39c8c45fd3cc2baa0ee4c8af7669202a' ) tr.set_text(utt) originLang = tr.detect_lang() tr.set_from_lang(originLang) tr.set_to_lang(languages[0]) tr.set_text(utt) utt = tr.translate() for i, lan in enumerate(languages): tr.set_from_lang(lan) if i < len(languages) - 1: tr.set_to_lang(languages[i + 1]) else: tr.set_to_lang(originLang) utt = tr.translate() tr.set_text(utt) #print(utt) return utt
def traduceEplan(cadenaEntrada): """esta funcion va a devolver la cadena compuesta y traducida a partir de una cadena de entrada""" #print "----> " + str(cadenaEntrada) cadenaEntrada = str(cadenaEntrada) cadEs = "es_ES@" + cadenaEntrada + ';' #Primero traduccion al ingles apiTranslateEplan = """trnsl.1.1.20190308T091207Z.xxx""" tr = Translater() tr.set_key(apiTranslateEplan) tr.set_from_lang('es') tr.set_to_lang('en') tr.set_text(cadenaEntrada) cadEng = "en_US@" + tr.translate() + ";" # #Frances tr.set_to_lang('fr') tr.set_text(cadenaEntrada) cadFr = "fr_FR@" + tr.translate() + ";" cadFr = cadFr.replace("'", "''") #Aleman tr.set_to_lang('de') tr.set_text(cadenaEntrada) cadAle = "de_DE@" + tr.translate() + ";" # #Polaco # tr.set_to_lang('pl') # tr.set_text(cadenaEntrada) # cadPol = "pl_PL@" + tr.translate() + ";" cadenaSalida = cadEs + cadEng + cadFr + cadAle #+ cadPol return (cadenaSalida)
from wozzol import WozzolQuizUnit import os import requests from yandex.Translater import Translater tr = Translater() # Api key found on https://translate.yandex.com/developers/keys tr.set_key('trnsl.1.1.20200317T184210Z.859bd4e1e36decc9.54c5d73f715ded0f0b5e33e8f80d0eca61173b7d') tr.set_from_lang('es') tr.set_to_lang('en') def translate_word(word): tr.set_text(word) translation = tr.translate() return translation def convert_word_list_to_wozzol(word_list): with open('somefile.txt', 'a') as the_file: the_file.write('wozzol') the_file.write('Spanish : English') for word in word_list: the_file.write(f'{word.question} = {word.answer}') def convert_wiktionary(): file_path = os.path.join('web_pages', 'spanish_1000_frequency.html') # format from https://www.wozzol.nl/woordenlijsten text_file = open(file_path, encoding="utf-8") text_lines = text_file.readlines()
from yandex.Translater import Translater tr = Translater() tr.set_key( 'trnsl.1.1.20200119T075806Z.ba2fc76141b64141.3739322923782504e521bd76c8903e90835cb864' ) tr.set_from_lang('en') tr.set_to_lang('ta') tr.set_text("rice crop field few weeks after sowing of seeds.") txt = tr.translate()
from newspaper import Article import nltk, re, pprint from nltk import word_tokenize import string from yandex.Translater import Translater tr = Translater() tr.set_key( 'trnsl.1.1.20190620T080928Z.059272b876400ab5.db9848757da3b1698721fef656db05d4903c4d1b' ) tr.set_from_lang('en') tr.set_to_lang('tr') nltk.download('words') nltk.download('stopwords') nltk.download('averaged_perceptron_tagger') #get stopwords, corpus-words from nltk.corpus import words from stop_words import get_stop_words from nltk.corpus import stopwords stop_words = list(get_stop_words('en')) #Have around 900 stopwords nltk_words = list(stopwords.words('english')) #Have around 150 stopwords stop_words.extend(nltk_words) def fetch_words_from_news(url):
# Thresholding def thresholding(image): return cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1] # Set enviroment variable with path to tesseract trained data os.environ["TESSDATA_PREFIX"] = "data" # Setup spellchecker spell = SpellChecker() # Setup translater translater = Translater() translater.set_key(args["apikey"]) translater.set_from_lang('en') translater.set_to_lang('ru') # Load the input image and grab the image dimensions image = cv2.imread(args["image"]) orig = image.copy() (origH, origW) = image.shape[:2] # Set the new width and height and then determine the ratio in change # for both the width and height (newW, newH) = (args["width"], args["height"]) rW = origW / float(newW) rH = origH / float(newH) # Resize the image and grab the new image dimensions image = cv2.resize(image, (newW, newH)) (H, W) = image.shape[:2]
def sendEmail(target_email,url,tmrange,etype): df = pd.read_csv('feedback-256010.csv') edf = pd.read_csv('email_records.csv') if url == "EMEA": csites = ["cs_CZ","en_UK","nl_BE","da_DK","en_ZA","nl_NL","de_AT","es_ES","pl_PL","de_CH","fr_BE","pt_pt","de_DE","fr_CH","ru_RU","en_IE","fr_FR","sv_SE","en_IL","it_IT","tr_TR","en_MDE"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "North America": csites = ["en_NA"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "APAC": csites = ["zh_CN","ja_JP","zh_TW","en_SEA","ko_KR","en_AU","en_NZ","en_IN"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "LAR": csites = ["en_CAR","es_CL","es_PE","es_CAR","es_CO"] down_df = df[df['Source URL'].str.contains('|'.join(csites))] elif url == "rockwellautomation.com/search": csites = ['rockwellautomation.com/search','rockwellautomation.com/my/search'] down_df = df[df['Source URL'].str.contains('|'.join(csites))] else: down_df = df[df['Source URL'].str.contains(url)] today = datetime.now() timzo = pytz.timezone('US/Eastern') today = timzo.localize(today) week_prior = today - timedelta(weeks=tmrange) down_df['Date Submitted'] = pd.to_datetime(down_df['Date Submitted']) down_df['Date Submitted']=down_df['Date Submitted'].dt.tz_localize(tz='US/Eastern', nonexistent='shift_forward') date_df = down_df.loc[down_df['Date Submitted'] >= week_prior] #Cancel if no feedback at all in past week #if date_df.empty == True: #print("No data for time given, email not sent for "+str(url)) #return testemail = MIMEMultipart() sender_email = "*****@*****.**" pw = "Ao1HO2RO3" #target_email = "*****@*****.**" testemail["From"] = sender_email testemail["To"] = target_email testemail["Subject"] = "Hotjar feedback from "+week_prior.strftime("%m/%d")+" to "+ today.strftime("%m/%d")+" | "+str(url) if etype == 'Responses': mess_df=date_df.loc[date_df["Message"].notna()] mess_df = mess_df.drop(columns=['Number',"User","OS"]) htmlbod = '<html><body><h1>Hotjar feedback over past '+str(tmrange)+' week(s) for '+str(url)+'</h1>' if mess_df.empty == True: htmlbod = '<html><body><p>No feedback responses for '+str(url)+' over '+str(tmrange)+' week(s).</p>' #Emjois: 5: 128522,1F60A 4: 128527, 1F60F 3: 128528, 1F610 2: 128530 1F612 1: 128544, 1F620 #Link : 128279, 1F517 emo = '128528' from yandex.Translater import Translater from langdetect import detect for row in mess_df.itertuples(): if str(row.Email)=="nan": email = '<b>(unknown)</b>' else: email = '<b>'+str(row.Email)+'</b>' if row._7==1: emo='128544' elif row._7==2: emo='128530' elif row._7==3: emo='128528' elif row._7==4: emo='128527' elif row._7==5: emo='128522' try: detlan = detect(str(row.Message)) except: detlan = 'en' if detlan == 'en': htmlbod = htmlbod+'<p><q>'+str(row.Message)+'</q></p><p>&#'+emo+email+' on '+row._1.strftime("%m/%d/%Y, %H:%M:%S")+" | "+str(row.Country)+" | "+str(row.Browser)+" on "+str(row.Device)+'</p><a href='+str(row._3)+'>🔗'+str(row._3)+'</a><hr>' else: try: tr = Translater() tr.set_key('trnsl.1.1.20200326T171128Z.c6e42851517b0a0a.363c0f12f70ef655b2ea466b33e40856c53df6c8') tr.set_text(str(row.Message)) tr.set_to_lang('en') mtrans = tr.translate() except: mtrans = "Translation failed." htmlbod = htmlbod+'<p><q>'+str(row.Message)+'</q></p><p>Translation attempt: <q>'+mtrans+'</q></p><p>&#'+emo+email+' on '+row._1.strftime("%m/%d/%Y, %H:%M:%S")+" | "+str(row.Country)+" | "+str(row.Browser)+" on "+str(row.Device)+'</p><a href='+str(row._3)+'>🔗'+str(row._3)+'</a><hr>' htmlbod = htmlbod + '</body></html>' testemail.attach(MIMEText(htmlbod, "html")) if etype == 'Visualizations': histfig = px.histogram(date_df, x='Date Submitted', color='Emotion (1-5)', title='Feedback Responses for '+str(url), opacity=0.8, category_orders={'Emotion (1-5)':[1,2,3,4,5]}, color_discrete_map={1:"#e83b3a",2:"#c97d7d",3:"#BAB0AC",4:"#99bd9c",5:"#4cba76"}, nbins=20 ) histfig.update_layout(xaxis_tickformat='%d %B (%a)', xaxis=dict(dtick=86400000.0)) histfig.write_image('histfigtest.png') counfig = px.histogram(date_df, y='Country', color='Emotion (1-5)', title='Breakdown by Country for url given', opacity=0.8, orientation = 'h', height = 1000, category_orders={'Emotion (1-5)':[1,2,3,4,5]}, color_discrete_map={1:"#e83b3a",2:"#c97d7d",3:"#BAB0AC",4:"#99bd9c",5:"#4cba76"}, #nbins=20 ).update_yaxes(categoryorder="total ascending") counfig.write_image('counfig.png') apdate_df=date_df apdate_df['feedback_count']= apdate_df['Source URL'].map(apdate_df['Source URL'].value_counts()) bad_df = apdate_df.loc[(apdate_df['Emotion (1-5)'] == 1) | (apdate_df['Emotion (1-5)'] == 2)] intr_df = bad_df[bad_df.duplicated(subset='Source URL', keep=False)] bdap_df=intr_df bdap_df['negative_feedbacks']= bdap_df['Source URL'].map(bdap_df['Source URL'].value_counts()) intrfig = px.scatter(bdap_df, title='Pages of interest (Which pages are getting lots of bad feedback?)', y='Source URL', x='negative_feedbacks', color='negative_feedbacks', text='feedback_count', color_continuous_scale=px.colors.sequential.YlOrRd, size='feedback_count') intrfig.update_layout(margin=dict(l=500,r=10,t=40,b=20),xaxis=dict(dtick=1)) intrfig.layout.coloraxis.showscale = False dd_df = bdap_df.drop_duplicates(subset='Source URL', keep='first') nlarg_df = dd_df.nlargest(5,['negative_feedbacks']) with open('histfigtest.png', 'rb') as f: # set attachment mime and file name, the image type is png mime = MIMEBase('image', 'png', filename='img1.png') # add required header data: mime.add_header('Content-Disposition', 'attachment', filename='img1.png') mime.add_header('X-Attachment-Id', '0') mime.add_header('Content-ID', '<0>') # read attachment file content into the MIMEBase object mime.set_payload(f.read()) # encode with base64 encoders.encode_base64(mime) # add MIMEBase object to MIMEMultipart object testemail.attach(mime) with open('counfig.png', 'rb') as f: # set attachment mime and file name, the image type is png mime = MIMEBase('image', 'png', filename='img2.png') # add required header data: mime.add_header('Content-Disposition', 'attachment', filename='img2.png') mime.add_header('X-Attachment-Id', '1') mime.add_header('Content-ID', '<1>') # read attachment file content into the MIMEBase object mime.set_payload(f.read()) # encode with base64 encoders.encode_base64(mime) # add MIMEBase object to MIMEMultipart object testemail.attach(mime) with open('intrfig.png', 'rb') as f: # set attachment mime and file name, the image type is png mime = MIMEBase('image', 'png', filename='img3.png') # add required header data: mime.add_header('Content-Disposition', 'attachment', filename='img3.png') mime.add_header('X-Attachment-Id', '2') mime.add_header('Content-ID', '<2>') # read attachment file content into the MIMEBase object mime.set_payload(f.read()) # encode with base64 encoders.encode_base64(mime) # add MIMEBase object to MIMEMultipart object testemail.attach(mime) embimg = '<html><body><h1>HotJar Report</h1>'+'<p><img src="cid:0"></p>'+'<img src="cid:1"></p>'+'<img src="cid:2"></p>'+'</body></html>' testemail.attach(MIMEText(embimg, 'html','utf-8')) session = smtplib.SMTP('smtp.gmail.com', 587, None, 30) session.starttls() session.login(sender_email, pw) session.set_debuglevel(1) text = testemail.as_string() session.sendmail(sender_email, target_email, text) session.quit() rec_dict = {"Date":today, "Recipient":target_email, "URL":url, "Email_type":etype} nedf = pd.DataFrame(rec_dict, index=[0]) upd_edf = edf.append(nedf, ignore_index = True) upd_edf.to_csv('email_records.csv', index = False) st.write("Email for "+str(url)+" sent to "+str(target_email))
import locale from yandex.Translater import Translater tr=Translater() locale.setlocale(locale.LC_ALL, '') #фиксит проблему с библиотекой яндекса api_key="trnsl.1.1.20200309T060830Z.344d9b14a5d60014.73173e69fc28c824b2288d084ca8e11617d260e1" query='boss' tr.set_key(api_key) tr.set_from_lang('en') tr.set_to_lang('ru') tr.set_text(query) result=tr.translate() speak(result)
def init_yandex_service(): tr = Translater() tr.set_key(initdata.yandex_token()) tr.set_from_lang('en') tr.set_to_lang('ru') return tr
Generates a json from the list return by get_tryalgo_descriptions(), and saves it in data/description.json :param translate: boolean passed to get_tryalgo_descriptions() """ description_obj = get_tryalgo_descriptions(translate=translate) description_file = os.path.join("..", "data", "description.json") with open(description_file, "w") as f: f.write(json.dumps(description_obj)) if __name__ == "__main__": if len(sys.argv) > 2: args_error() if len(sys.argv) == 2: if sys.argv[1] != "--no-translation": args_error() generate_json(translate=False) else: tr = Translater() yandex_key = get_yandex_key() tr.set_key(yandex_key) tr.set_from_lang('en') tr.set_to_lang('fr') generate_json(translate=True)
# IMPORT THE YANDEX TRANSLATE API ENGINE TO OUR PYTHON APP SCRIPT from yandex.Translater import Translater # APP SET NAME AND VERSION | INSERT YOUR APP DETAILS, SUCH AS NAME AND VERSION print('Welcome to landRev | appDrew Development') # APP INITIALIZE THE YANDEX ENGINE TRANSLATOR tr = Translater() # APP INITIALIZE THHE API KEY FOR YANDEX ENGINE TRANSLATOR | INSERT YOUR API KEY BELLOW PLEASE. tr.set_key('YOUR YANDEX API KEY HERE') # APP SET THE MAIN LANGUAGE | INSERT YOUR MAIN LANGUAGE "FROM WHAT LANGUAGE TO TRANSLATE" tr.set_from_lang('en') # APP SET the TRANSLATION LANGUAGE | INSERT YOUR TRANSLATION LANGUAGE WITH LANG CODE tr.set_to_lang('es') INPUT_TEXT_DATA = input('What do you would like to translate ? : ') #SET THE INPUT_TEXT_DATA FOR TANSLATOR ENGINE TO TRANSLATE THE STRINGS tr.set_text(INPUT_TEXT_DATA) #PRINT OUT THE TRANSLATED DATA RESULTS results = tr.translate() print(results)