|
import requests |
|
import json |
|
import gradio as gr |
|
import pandas as pd |
|
import os |
|
|
|
url = os.environ['typo_url'] |
|
api_key = os.environ['api-key'] |
|
|
|
|
|
def request_service(text,words): |
|
words = words.split("\n") |
|
results = [] |
|
texts = [] |
|
for t in text.split("\n")[:20]: |
|
if len(t.strip())>2: |
|
texts.append(t) |
|
payload={"text":t ,"special_words": words} |
|
headers = { |
|
'x-api-key': api_key, |
|
'Content-Type': 'application/json' |
|
} |
|
|
|
response = requests.request("POST", url, headers=headers, data=json.dumps(payload)) |
|
results.append(json.loads(response.text)['result'].replace('ü','ü').replace('ı','ı').replace('ÅŸ','ş').replace('ö','ö').replace('ç','ç').replace('ÄŸ','ğ')) |
|
|
|
return pd.DataFrame({'Result':results,'Sentence':texts}) |
|
|
|
|
|
import gradio as gr |
|
|
|
def clear_text(text): |
|
return '',pd.DataFrame() |
|
|
|
|
|
default_str ='''bircümlebitişikdahiolsabucümleyiayırabiliyoruz |
|
yazim hatalarini da duzeltebiliyorz |
|
ssl hrf lms d dzltblyrz |
|
''' |
|
special_word_list ='''artificial |
|
nlp |
|
''' |
|
|
|
css = """.gradio-container {background-color: #DBDEDF } |
|
#clearbtn {background-color: red} |
|
#submitbtn {background-color: green} |
|
#logbtn {background-color: blue} |
|
#header {color:#973410; font-size: 30px;font-weight: bold; } |
|
footer {visibility: hidden} |
|
#textbox {color:white} |
|
#texts {color:3E5E69;font-size: 15px;font-weight: bold; } |
|
#results {color:3E5E69;font-size: 20px;font-weight: bold; } |
|
label:{font-size:30px}""" |
|
with gr.Blocks(title="Typo Correction",css=css) as demo: |
|
gr.Markdown('Turkish Typo Correction',elem_id ='header') |
|
gr.Markdown("""* You can enter your misspelled sentences in the Sentences section. |
|
* In the Special Words section, you can enter your special words that you do not want the model to correct. |
|
""",elem_id ='texts') |
|
with gr.Column(): |
|
sentences = gr.Textbox(label="Sentences",lines = 8,value=default_str,elem_id='textbox') |
|
special_words = gr.Textbox(label="Special Words",lines = 2,value=special_word_list,elem_id='textbox') |
|
|
|
|
|
correct_btn = gr.Button("Correct Typos",elem_id = 'submitbtn') |
|
clear_btn = gr.Button("Reset",elem_id="clearbtn") |
|
gr.Markdown('RESULTS',elem_id ='results') |
|
output = gr.Dataframe() |
|
correct_btn.click(fn=request_service, inputs=[sentences,special_words], outputs=output) |
|
|
|
clear_btn.click(fn=clear_text,inputs=special_words,outputs=[sentences,output]) |
|
|
|
demo.launch() |