prajdabre commited on
Commit
7414d79
1 Parent(s): 797b28f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -40
app.py CHANGED
@@ -14,12 +14,12 @@ pad_id = tokenizer._convert_token_to_id_with_added_voc("<pad>")
14
  CREOLE = {"Hawaiian Pidgin": "hwc", "Saint Lucian Creole": "acf", "Belizean Creole": "bzj", "Chavacano Creole": "cbk", "Seychellois Creole": "crs", "Sranan Tongo": "srn", "Aukan": "djk", "Gullah": "gul", "San Andrés–Providencia Creole": "icr", "Jamaican Creole": "jam", "Mauritian Creole": "mfe", "Papiamento": "pap", "Pijin": "pis", "Tok Pisin": "tpi", "Torres Strait Creole": "tcs", "Australian Kriol": "rop", "Sango": "sag", "Saramaccan": "srm", "Bislama": "bis", "Nigerian": "pcm", "Sierra Leonean Creole": "kri", "Haitian Creole": "hat", "Kupang Malay": "mkn", "Tetun Dili": "tdt", "Malay Baba": "mbf", "Kituba": "ktu"}
15
 
16
 
17
- def generate(input, task, lang):
18
  lang = CREOLE[lang]
19
- inp = tokenizer(input.strip() + " </s> <2" + lang + ">",
20
  add_special_tokens=False, return_tensors="pt", padding=True).input_ids
21
  model_output = model.generate(inp, use_cache=True, num_beams=1, max_length=100, min_length=1, early_stopping=True, pad_token_id=pad_id,
22
- bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2"+lang+">"))
23
  decoded_output = tokenizer.decode(
24
  model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
25
 
@@ -29,50 +29,45 @@ def generate(input, task, lang):
29
  languages = list(INDIC.keys())
30
 
31
  src_language_drop_down = gr.inputs.Dropdown(
32
- languages, type="value", default="Hindi", label="Select source language")
33
  tgt_language_drop_down = gr.inputs.Dropdown(
34
- languages, type="value", default="Hindi", label="Select target language")
35
  text = gr.inputs.Textbox(lines=1, placeholder="Enter text here...",
36
- default="", label="Enter text in the desired language")
37
  text_ouptut = gr.outputs.Textbox(
38
  type="auto", label="View translation in the target language")
39
 
40
  supported_lang = ', '.join(languages)
41
 
42
  # examples = [
43
- [u"<TAG> name </TAG> राम नरेश पांडेय <TAG> office </TAG> विधायक - 205 - कुशीनगर विधान सभा निर्वाचन क्षेत्र , उत्तर प्रदेश <TAG> term </TAG> 1967 से 1968 <TAG> nationality </TAG> भारतीय", "IndicWikiBio", "Hindi"],
44
- # [u"वैश्विक व्यापार युद्ध की शिकार हुई तुर्की की मुद्रा लीरा के डूबने से अमेरिकी डॉलर के मुकाबले रुपया अब तक के न्यूनतम स्तर पर पहुंच गया। रुपये में रिकॉर्ड गिरावट से सोने की चमक में निखार नहीं आ सकी। वैश्विक बाजार में सोना करीब आठ महीने के निचले स्तर पर पहुंच गया तो घरेलू बाजार में यह करीब नौ महीने के निचले स्तर पर चला गया। वैश्विक मंदी की आशंका से वैश्विक बाजार में चांदी करीब ढाई साल और घरेलू बाजार में तकरीबन नौ महीने के निचले स्तर पर पहुंच गई। तुर्की की आर्थिक चिंता के कारण अमेरिकी डॉलर के मुकाबले रुपया कारोबार के दौरान 70.80 के स्तर तक गिर गया। यह इसका ऐतिहासिक रिकॉर्ड निम्न स्तर है। कमजोर रुपये से सोने की चमक बढऩे की उम्मीद की जा रही थी लेकिन वैश्विक बाजार में सोने की कीमत गिरकर 1,193.50 डॉलर प्रति औंस पहुंचने के कारण घरेलू बाजार में भी सोने की चमक फीकी पड़ गई। घरेलू बाजार में सोना गिरकर 29,655 रुपये प्रति 10 ग्राम पहुंच गया। घरेलू वायदा बाजार यानी एमसीएक्�� पर सोना 29,700 के आस-पास कारोबार कर रहा है। देश में इस साल सोने की मांग में लगातार गिरावट देखने को मिल रही थी। अप्रैल-जून तिमाही में सोने का आयात 25 फीसदी से भी कम हुआ है। चालू महीने में सोने की मांग बढऩे की उम्मीद जगी थी लेकिन यह उम्मीद टूट सकती है क्योंकि दुनिया के सबसे बड़े गोल्ड फंड एसपीडीआर गोल्ड की होल्डिंग अप्रैल के बाद 10 फीसदी गिर चुकी है। इस समय यह पिछले ढाई साल के निचले स्तर पर है। इस साल वैश्विक बाजार में सोना करीब 8.5 फीसदी और घरेलू बाजार में 1.5 फीसदी टूट चुका है। सराफा मामलों के जानकार अनिल अग्रवाल कहते हैं कि वैश्विक हालात ऐसे हैं कि इस समय निवेशक डॉलर में पैसा लगा रहे हैं। इस कारण दूसरी मुद्रा और जिंस दबाव में हैं। हालांकि हालात यही रहे तो सोने में तेज सुधार भी देखने को मिलेगा। वैश्विक मंदी की बढ़ती आशंका का सबसे ज्यादा असर चांदी पर पड़ रहा है। वैश्विक बाजार में चांदी के दाम ढाई साल के निचले स्तर पर पहुंच चुके हैं। वैश्विक बाजार में चांदी की कीमत 15 डॉलर प्रति औंस के करीब चल रही है। इसके पहले अप्रैल 2016 में चांदी इस स्तर पर थी। वैश्विक बाजार में चांदी के दाम दो महीने पहले 18.13 डॉलर प्रति औंस पर चल रहे थे। चांदी कारोबारी राहुल मेहता कहते हैं कि सोना और मूल धातु में कमजोरी से चांदी पर दोहरा दबाव पड़ रहा है। वैश्विक बाजार का व्यापार युद्ध अब मुद्रा युद्ध में बदल गया है। वैश्विक अर्थव्यवस्था एक बार फिर मंदी की गिरफ्त में आ सकती है जिसके कारण औद्योगिक विकास भी प्रभावित होगा। यही वजह है कि चांदी की कीमतें लगातार लुढक़ रही हैं क्योंकि मांग में कमी आने की आशंका बढ़ती जा रही है। फिलहाल घरेलू बाजार में चांदी 37,825 रुपये प्रति किलोग्राम पर बिक रही है। तुर्की के आर्थिक संकट से एक बार फिर वैश्विक मंदी का डर है जिसका असर दुनियाभर के बाजारों पर देखा जा सकता है। इसने विश्व स्तर पर निवेशकों के रुख को प्रभावित किया है और वे डॉलर को एक सुरक्षित निवेश के तौर पर देख रहे हैं। आनंद राठी शेयर्स ऐंड स्टाक ब्रोकर्स में शोध विश्लेषक आर मारू ने कहा कि आयातकों की अधिक मांग से रुपये की विनिमय दर में गिरावट आई। उन्होंने कहा, तुर्की संकट को लेकर अनिश्चितता तथा डॉलर सूचकांक में तेजी को देखते हुए आयातक आक्रमक तरीके से डॉलर की लिवाली कर रहे हैं। दूसरी तरफ आरबीआई की तरफ से आक्रमक हस्���क्षेप न होने से भी रुपया नीचे आया। सरकार ने अमेरिकी डॉलर के मुकाबले रुपये के अब तक के न्यूनतम स्तर पर पहुंचने के लिए बाह्य कारकों को जिम्मेदार ठहराते हुए कहा कि इसमें चिंता की कोई बात नहीं है।", "IndicHeadlineGeneration", "Hindi"],
45
- # [u"दिल्ली यूनिवर्सिटी देश की प्रसिद्ध यूनिवर्सिटी में से एक है.",
46
- "IndicParaphrasing", "Hindi"],
47
- # [u"जम्मू एवं कश्मीर के अनंतनाग जिले में शनिवार को सुरक्षाबलों के साथ मुठभेड़ में दो आतंकवादियों को मार गिराया गया।",
48
- "IndicSentenceSummarization", "Hindi"],
49
- # [u"7 फरवरी, 2016 [SEP] खेल 7 फरवरी, 2016 को कैलिफोर्निया के सांता क्लारा में सैन फ्रांसिस्को खाड़ी क्षेत्र में लेवी स्टेडियम में खेला गया था।",
50
- "IndicQuestionGeneration", "Hindi"]
51
- #]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  iface = gr.Interface(fn=generate, inputs=[text, src_language_drop_down, tgt_language_drop_down], outputs=text_ouptut, title='CreoleM2M System',
54
- description='Currently the model supports ' + supported_lang, examples=examples)
55
- iface.launch(enable_queue=True)
56
-
57
- # with gr.blocks.Blocks() as block:
58
- # input = gr.Textbox(label="Input")
59
- # task = gr.Dropdown(["IndicWikiBio", "IndicHeadlineGeneration", "IndicParaphrasing",
60
- # "IndicSentenceSummarization", "IndicQuestionGeneration"], label="Task")
61
- # lang = gr.Dropdown(["as", "bn", "gu", "hi", "kn", "ml",
62
- # "mr", "or", "pa", "ta", "te"], label="Language")
63
- # generate = gr.Button("Generate")
64
- # output = gr.Textbox()
65
- # instructions = gr.HTML("<h1>How to use:</h1><br>\
66
- # 1. This space supports 5 tasks and 11 Indic languages.<br>\
67
- # 2. First select the task from the dropdown box and it will show you an example of Input for Hindi. This default example display will be automated for each language in the future. Choose your language, give your input and then press the generate button. Note the formats for IndicWikiBio and Question generation when testing your own inputs. Also note that if you choose another task then the input will be replaced with the default example for that task.<br>\
68
- # 3. The tasks are:<br>\
69
- # 3.1 IndicWikiBio where the input is a Wikipedia table and the output will be a one sentence biograpy. You should pass the input in the following format: &lt;TAG&gt; key1 &lt;/TAG&gt; value1 &lt;TAG&gt; key2 &lt;/TAG&gt; value2.<br>\
70
- # 3.2 IndicHeadlineGeneration where the input is a document or paragraph the output will be a short title. Copy a paragraph from your favorite news site and get a headline. Dont paste extemely long paragraphs. You have been warned.<br>\
71
- # 3.3 IndicParaphrasing where the input is a sentence and the output is its paraphrase.<br>\
72
- # 3.4 IndicSentenceSummarization where the input is a long sentence and the output is a compact version of that sentence.<br>\
73
- # 3.5 IndicQuestionGeneration where the input is an answer and context and the output is the question that should be asked to get the answer. You should pass the input in the following format: ANSWER [SEP] CONTEXT.\
74
- # ")
75
- # task.change(set_example, inputs=[task, lang], outputs=[input, lang])
76
- # generate.click(greet, inputs=[input, task, lang], outputs=output)
77
- # block.launch()
78
-
 
14
  CREOLE = {"Hawaiian Pidgin": "hwc", "Saint Lucian Creole": "acf", "Belizean Creole": "bzj", "Chavacano Creole": "cbk", "Seychellois Creole": "crs", "Sranan Tongo": "srn", "Aukan": "djk", "Gullah": "gul", "San Andrés–Providencia Creole": "icr", "Jamaican Creole": "jam", "Mauritian Creole": "mfe", "Papiamento": "pap", "Pijin": "pis", "Tok Pisin": "tpi", "Torres Strait Creole": "tcs", "Australian Kriol": "rop", "Sango": "sag", "Saramaccan": "srm", "Bislama": "bis", "Nigerian": "pcm", "Sierra Leonean Creole": "kri", "Haitian Creole": "hat", "Kupang Malay": "mkn", "Tetun Dili": "tdt", "Malay Baba": "mbf", "Kituba": "ktu"}
15
 
16
 
17
+ def generate(input, task, slang, tlang):
18
  lang = CREOLE[lang]
19
+ inp = tokenizer(input.strip() + " </s> <2" + slang + ">",
20
  add_special_tokens=False, return_tensors="pt", padding=True).input_ids
21
  model_output = model.generate(inp, use_cache=True, num_beams=1, max_length=100, min_length=1, early_stopping=True, pad_token_id=pad_id,
22
+ bos_token_id=bos_id, eos_token_id=eos_id, decoder_start_token_id=tokenizer._convert_token_to_id_with_added_voc("<2"+tlang+">"))
23
  decoded_output = tokenizer.decode(
24
  model_output[0], skip_special_tokens=True, clean_up_tokenization_spaces=False)
25
 
 
29
  languages = list(INDIC.keys())
30
 
31
  src_language_drop_down = gr.inputs.Dropdown(
32
+ languages, type="value", default="Hawaiian Pidgin", label="Select source language")
33
  tgt_language_drop_down = gr.inputs.Dropdown(
34
+ languages, type="value", default="English", label="Select target language")
35
  text = gr.inputs.Textbox(lines=1, placeholder="Enter text here...",
36
+ default="", label="Enter text in the source language")
37
  text_ouptut = gr.outputs.Textbox(
38
  type="auto", label="View translation in the target language")
39
 
40
  supported_lang = ', '.join(languages)
41
 
42
  # examples = [
43
+ # ['Mé sòlda-a mawé'y pou yo bat li , Pòl di ofisyé-a ki doubout la-a , “ Ès lwa-a di ou sa bat on jan Ronm si ou p'òkò menm lodyans pou sa ? ”', "acf", "eng"],
44
+ # ['Be taem oli fasemgud hem blong wipim hem , Pol i talem long kapten blong olgeta , we i stap stanap long ples ya se , ! E ! Mi mi sitisen blong Rom ya . Yufala i no jajem mi yet . ! Olsem wanem yufala i wantem wipim mi ? ”', "bis", "eng"],
45
+ # ['Wail di soalja dehn mi-di tai op Paal fi beet ahn , Paal aks wan a di aafisa dehn weh mi-di stan op kloas tu ahn , “ Tel mi , ih leegal fi beet wahn Roaman sitizn bifoa unu chrai ahn da koat ? ”', "bzj", "eng"],
46
+ # ['Mientras ta amarra sila con Pablo para latiga , ya habla le con el capitan quien talla parao , “ Tiene ba uste el derecho para latiga con un ciudadano Romano que nuay pa pasa investigacion de algun crimen ? ”', "cbk", "eng"],
47
+ # ['Kan zot ti'n anmar li pour li ganny fwete , Pol ti dir avek sa zofisye ki ti la , “ Eski ou annan drwa fwet en sitwayen Romen ki pa'n ganny zize ? ”', "crs", "eng"],
48
+ # ['Den tei en poti fu leli buba . Ma a piki a ofisii di mu meke den du dati taki : “ U tei mi enke foluku fu Loma Foto fu wipi ondoosuku ! Ma kownu anda weiti taki : ‘ Na lanti fu kuutu mu ondoosuku foluku fu Loma Foto . A sowtu wipi ya a ganda mindii noiti mu pasa . ’ ”', "djk", "eng"],
49
+ # ['Bot wen dey tie Paul op an scretch um out fa beat um , Paul taak ta de offisa wa beena stanop dey . Paul aks um say , “ De law ain tell oona dat oona kin beat a Roman citizen wen nobody ain eben jedge um , needa find out dat e done sompin bad , ainty dough ? ”', "gul", "eng"],
50
+ # ['Wen dey wen stretch him out fo whip him real hard , Paul wen tell da captain dat stay dea , “ Dis okay in da rules fo da Rome peopo ? fo you fo whip one guy dat get da same rights jalike da Rome peopo ? even one guy dat neva do notting wrong ? ”', "hwc", "eng"],
51
+ # ['Wail di suoldya dehn wende tai op Paul fi biit im , Paul aks wan a di aafisa weh wende stan op gens im , “ Tel mi , sah , ih liigal fi biit wan Roman sitizn bifuor unu trai im dah kuot ? ”', "icr", "eng"],
52
+ # ['Afta dem tai im op an chrech im out fi biit im , Paal aks di ed fi onjrid suoja we did tan op de , “ Di Laa gi yu no rait fi biit mi , wan man we kom fram Ruom , wen yu no iivn kyari mi go a kuot an se mi gilti fi notn ? ”', "jam", "eng"],
53
+ # ['Bɔt wɛn dɛn want bit am , dɛn tay am ; na in Pɔl aks di soja man dɛn edman we bin tinap de se , “ Di lɔ tɛl una se una kin bit pɔsin we na Roman wɛn una nɔ jɔj am yet ? ”', "kri", "eng"],
54
+ # ['Me letan zot fini atas li pou kapav fwet li , Pol dir ofisie ki ti la , “ Zot ena drwa fwet enn sitwayin Romin san mem ki zot ziz li ? ”', "mfe", "eng"],
55
+ # ['Ma ora nan a rèk su kurpa pa sut’é ku zuip , Pablo a bisa e ofisial di ehérsito pará einan : “ Boso tin mag di suta un hende ku ta siudadano romano sin ku e ta kondená ? ”', "pap", "eng"],
56
+ # ['Wen dem don put am for groun mak dem start to flog am , Pol kon ask di soja wey stand near am , " E dey rite mak una flog pesin wey bi Roman citizin , wen dem neva joj en kase ? "', "pcm", "eng"],
57
+ # ['Bat taem olketa taengem hand bilong hem long post for whipim hem , Paul sei olsem long bigman bilong army wea standap long there : “ Hao , hem stret for iufala whipim wanfala man bilong Rome wea iufala no kotem hem yet ? ”', "pis", "eng"],
58
+ # ['en wen deibin taiyimap Pol blanga beldim im , imbin tok langa det boswan solja hubin jandap deya wansaid langa im . Imbin tok , “ Yumob nomo lau beldim mi , dumaji mi garram det rait seimwei laik ol yumob Roman pipul , en ai nomo bin abum kotkeis yet . ”', "rop", "eng"],
59
+ # ['Me tongana ala leke lo ti tene a pika lo na zaza , Paul atene na turugu ti kota kamba so ayeke luti na ndo so : “ Ndia amû lege na ALA ti pika na zaza mbeni koli so ayeke Romain na so a dë ngbanga na li ti lo pëpe ? ”', "sag", "eng"],
60
+ # ['Hën de tjëën go seeka tai fu de hupi . Hën Paulosu hakisi di kabiteni u sodati taanputaanpu dë taa : “ Unfa di wëti dë ? Un sa hupi wan goon mii u Loomë ufö un kuutu soni fëën ö ? ”', "srm", "eng"],
61
+ # ['Ma di den poti Paulus didon langalanga fu wipi en , dan a taigi a legre-ofsiri di ben e tanapu drape : „ A fiti taki unu e wipi wan Romesma sondro fu krutu en ? ”', "srn", "eng"],
62
+ # ['Bat wen dempla i bin mekpas Pol so dempla ken ploke em , Pol i bin spik po da sekan amiopisa uda bin stanap klostu wea em . Pol i bin spik , ‘ Ei yu ! Yu lau po ploke man uda gad rait wase man prom Rom , bipo yupla teke em po kot a ? ’', "tcs", "eng"],
63
+ # ['Tasol taim ol i apim 2-pela han bilong en na pasim bilong wipim em , Pol i tokim ofisa bilong ami i sanap klostu olsem : “ I stret yupela i wipim wanpela man Rom taim em i no bin sanap yet long kot ? ”', "tpi", "eng"],
64
+ # ['Men , lè yo fin mare Pòl pou yo bat li , li di ofisye ki te la a : “ Èske NOU gen dwa bat yon sitwayen women ki pa kondane ? ”', "hat", "eng"],
65
+ # ['Waktu dong ika sang Paulus ko mau firuk sang dia , ju dia bale tanya sang itu tantara , bilang , “ Iko pamarenta Roma pung atoran , mana yang batúl ? Kalo satu orang ada pung hak warga Roma , ais dia dapa parkara , bosong musti bekin karmana sang dia ? Bosong papoko lebe dolo sang dia , ko , bosong pareksa lebe dolo ? ”', "mkn", "eng"],
66
+ # ['Maibé kuandu sira kesi tiha nia atu baku nia ho xikote , Paulo dehan ba kapitaun tropa nian neʼebé hamriik besik : “ Tuir lei , imi bele baku ema Roma ida maski seidauk tesi lia ba nia ka lae ? ”', "tdt", "eng"],
67
+ # ['Bila dia-orang sudah ikatkan dia dngan tali kulit , Paulus kata sama itu hulubalang yang berdiri dkat situ , " Kalau satu anak Rom blum kna hukum , ada-kah patut angkau ssahkan dia ? "', "mbf", "eng"],
68
+ # ['Bu bau imene kukanga yandi sambu na kubula yandi fimbe , Paulu tubaka kwa nkuluntu ya telemaka kuna : Nsiku pesa nzila kubula muntu ya Loma fimbu ya imene kufunduswa ve ?', "ktu", "eng"]
69
+ # ]
70
 
71
  iface = gr.Interface(fn=generate, inputs=[text, src_language_drop_down, tgt_language_drop_down], outputs=text_ouptut, title='CreoleM2M System',
72
+ description='Currently the model supports ' + supported_lang) #, examples=examples
73
+ iface.launch(enable_queue=True)