def wlhome():
    # This is how you do logging, in this case information messages.
    app.logger.info('wlhome page requested')
    allinfo = {}
    lang = 'TBD'
    txt = None
    form = LangForm()
    # If the form passes this check, then its a POST and the fields are valid.
    # ie. if the request is a GET then this check fails.
    if form.validate_on_submit():
        lang = 'TBC'
        txt = form.txtdata.data
        form.txtdata.data = ''

        try:
            language_translation = LanguageTranslation(
                username=
                '******',
                password='******')
            langsdetected = language_translation.identify(txt)
            primarylang = langsdetected["languages"][0]

            lang = "I am {confidence} confident that the language is {language}.".format(
                **primarylang)
            session['langtext'] = lang

            allinfo['lang'] = lang
            allinfo['form'] = form
            return redirect(url_for('wlhome'))
        except WatsonException as err:
            allinfo['error'] = err

    allinfo['lang'] = session.get('langtext')
    allinfo['form'] = form
    return render_template('watson/wlindex.html', info=allinfo)
示例#2
0
def index(request):
    allinfo = {}
    form = None
    if request.POST:
        form = Form_language(request.POST)
        if form.is_valid():
            data = form.cleaned_data['txtdata']
            logger.info("Text to be process is %s" % data)
            lang = "TBD"

            try:
                language_translation = LanguageTranslation(
                    username=
                    '******',
                    password='******')
                langsdetected = language_translation.identify(data)
                primarylang = langsdetected["languages"][0]['language']
                confidence = langsdetected["languages"][0]['confidence']

                lang = "I am %s confident that the language is %s" % (
                    confidence, primarylang)
            except WatsonException as err:
                allinfo['error'] = err

            allinfo['lang'] = lang
        else:
            allinfo['error'] = "The form is invalid"
    else:
        form = Form_language

    allinfo['form'] = form
    return render(request, 'watson/wlindex.html', allinfo)
def wlhome():
    # This is how you do logging, in this case information messages.
    app.logger.info('wlhome page requested')
    allinfo = {}
    lang = "TBD"
    txt = None
    form = LangForm()
    # If the form passes this check, then its a POST and the fields are valid. ie. if the 
    # request is a GET then this check fails.	
    if form.validate_on_submit():
        lang = "TBC"
        txt = form.txtdata.data
        form.txtdata.data = ''

        try:
            language_translation = LanguageTranslation(username='******',
                                                   password='******')
            langsdetected = language_translation.identify(txt)
            primarylang = langsdetected["languages"][0]['language']
            confidence = langsdetected["languages"][0]['confidence']

            lang = "I am %s confident that the language is %s" % (confidence, primarylang)            
            session['langtext'] = lang

            allinfo['lang'] = lang
            allinfo['form'] = form
            return redirect(url_for('wlhome'))
        except WatsonException as err:
          allinfo['error'] = err

    allinfo['lang'] = session.get('langtext')
    allinfo['form'] = form
    return render_template('watson/wlindex.html', info=allinfo)
def index(request):
  allinfo = {}
  form = None
  if request.POST:
    form = Form_language(request.POST)
    if form.is_valid():
      data = form.cleaned_data['txtdata']
      logger.info("Text to be process is %s" % data)
      lang = "TBD"

      try:
        language_translation = LanguageTranslation(username='******',
        	                                       password='******')
        langsdetected = language_translation.identify(data)
        primarylang = langsdetected["languages"][0]['language']
        confidence = langsdetected["languages"][0]['confidence']

        lang = "I am %s confident that the language is %s" % (confidence, primarylang)
      except WatsonException as err:
      	allinfo['error'] = err

      allinfo['lang'] = lang
    else:
      allinfo['error'] = "The form is invalid" 
  else:
    form = Form_language
    
  allinfo['form'] = form
  return render(request, 'watson/wlindex.html', allinfo)
# coding=utf-8
import json
from watson_developer_cloud import LanguageTranslationV2 as LanguageTranslation


language_translation = LanguageTranslation(username='******',
                                           password='******')

print(json.dumps(language_translation.get_models(), indent=2))

print(json.dumps(language_translation.translate('Hola, cómo estás? €', source='es', target='en'), indent=2,
                 ensure_ascii=False))


print(json.dumps(language_translation.identify('Hello how are you?'), indent=2))
# coding=utf-8
import json
from watson_developer_cloud import LanguageTranslationV2 as LanguageTranslation

language_translation = LanguageTranslation(username='******',
                                           password='******')

print(json.dumps(language_translation.get_models(), indent=2))

print(
    json.dumps(language_translation.translate('Hola, cómo estás? €',
                                              source='es',
                                              target='en'),
               indent=2,
               ensure_ascii=False))

print(json.dumps(language_translation.identify('Hello how are you?'),
                 indent=2))