File size: 2,606 Bytes
3c073e8
 
 
 
 
 
 
997bc99
3c073e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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')
        
        #output = gr.Textbox(label="Results",lines = 10,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()