Spaces:
Runtime error
Runtime error
burakaytan
commited on
Commit
•
3c073e8
1
Parent(s):
b84de62
Upload 2 files
Browse files- app.py +72 -0
- requirements.txt +1 -0
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import json
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
import os
|
6 |
+
|
7 |
+
url = os.environ['typo_url']
|
8 |
+
api_key = os.environ['api-key']
|
9 |
+
|
10 |
+
|
11 |
+
def request_service(text,words):
|
12 |
+
words = words.split("\n")
|
13 |
+
results = []
|
14 |
+
texts = []
|
15 |
+
for t in text.split("\n")[:20]:
|
16 |
+
if len(t.strip())>2:
|
17 |
+
texts.append(t)
|
18 |
+
payload={"text":t ,"special_words": words}
|
19 |
+
headers = {
|
20 |
+
'x-api-key': api_key,
|
21 |
+
'Content-Type': 'application/json'
|
22 |
+
}
|
23 |
+
|
24 |
+
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
|
25 |
+
results.append(json.loads(response.text)['result'].replace('ü','ü').replace('ı','ı').replace('ÅŸ','ş').replace('ö','ö').replace('ç','ç').replace('ÄŸ','ğ'))
|
26 |
+
|
27 |
+
return pd.DataFrame({'Result':results,'Sentence':texts})
|
28 |
+
|
29 |
+
|
30 |
+
import gradio as gr
|
31 |
+
|
32 |
+
def clear_text(text):
|
33 |
+
return '',pd.DataFrame()
|
34 |
+
|
35 |
+
|
36 |
+
default_str ='''bircümlebitişikdahiolsabucümleyiayırabiliyoruz
|
37 |
+
yazim hatalarini da duzeltebiliyorz
|
38 |
+
ssl hrf lms d dzltblyrz
|
39 |
+
'''
|
40 |
+
special_word_list ='''artificial
|
41 |
+
nlp
|
42 |
+
'''
|
43 |
+
|
44 |
+
css = """.gradio-container {background-color: #DBDEDF }
|
45 |
+
#clearbtn {background-color: red}
|
46 |
+
#submitbtn {background-color: green}
|
47 |
+
#logbtn {background-color: blue}
|
48 |
+
#header {color:#973410; font-size: 30px;font-weight: bold; }
|
49 |
+
footer {visibility: hidden}
|
50 |
+
#textbox {color:white}
|
51 |
+
#texts {color:3E5E69;font-size: 15px;font-weight: bold; }
|
52 |
+
#results {color:3E5E69;font-size: 20px;font-weight: bold; }
|
53 |
+
label:{font-size:30px}"""
|
54 |
+
with gr.Blocks(title="Typo Correction",css=css) as demo:
|
55 |
+
gr.Markdown('Turkish Typo Correction',elem_id ='header')
|
56 |
+
gr.Markdown("""* You can enter your misspelled sentences in the Sentences section.
|
57 |
+
* In the Special Words section, you can enter your special words that you do not want the model to correct.
|
58 |
+
""",elem_id ='texts')
|
59 |
+
with gr.Column():
|
60 |
+
sentences = gr.Textbox(label="Sentences",lines = 8,value=default_str,elem_id='textbox')
|
61 |
+
special_words = gr.Textbox(label="Special Words",lines = 2,value=special_word_list,elem_id='textbox')
|
62 |
+
|
63 |
+
#output = gr.Textbox(label="Results",lines = 10,elem_id='textbox')
|
64 |
+
correct_btn = gr.Button("Correct Typos",elem_id = 'submitbtn')
|
65 |
+
clear_btn = gr.Button("Reset",elem_id="clearbtn")
|
66 |
+
gr.Markdown('RESULTS',elem_id ='results')
|
67 |
+
output = gr.Dataframe()
|
68 |
+
correct_btn.click(fn=request_service, inputs=[sentences,special_words], outputs=output)
|
69 |
+
|
70 |
+
clear_btn.click(fn=clear_text,inputs=special_words,outputs=[sentences,output])
|
71 |
+
|
72 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
requests==2.28.2
|