File size: 2,596 Bytes
8810d44 f462bd2 4ff8b83 7676e0a 8810d44 86f6efe f462bd2 17eec93 f462bd2 17eec93 f462bd2 17eec93 f462bd2 17eec93 f462bd2 17eec93 f462bd2 e941c48 f462bd2 b213fb9 e941c48 0c235c9 86f6efe 4ff8b83 86f6efe |
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 |
import gradio as gr
import random
import fomula
from utils import *
def final_result(input_text):
total_change = 0
num_change = 0
list_do = random.sample(range(10), 10)
input_text_process = input_text
for i in list_do:
if i == 0:
##character_replacement
input_text_process, num_change = character_replacement(input_text_process, total_change / len(input_text), error_rate=0.01)
elif i == 1:
##character_insertion
input_text_process, num_change = character_insertion(input_text_process,total_change / len(input_text), error_rate=0.01)
elif i == 2:
##character_deletion
input_text_process, num_change = character_deletion(input_text_process,total_change / len(input_text), error_rate=0.01)
elif i == 3:
##character_transposition
input_text_process, num_change = character_transposition(input_text_process,total_change / len(input_text), error_rate=0.01)
elif i == 4:
##homophone_replacement
input_text_process, num_change = homophone_replacement(input_text_process,total_change / len(input_text), error_rate=0.01)
elif i == 5:
## common_misspelling_replacement
input_text_process, num_change = common_misspelling_replacement(input_text_process,total_change / len(input_text), error_rate=0.01)
elif i == 6:
##similar_character_replacement
input_text_process, num_change = similar_character_replacement(input_text_process,total_change / len(input_text), error_rate=0.01)
elif i == 7:
##random_space_insertion
input_text_process, num_change = random_space_insertion(input_text_process,total_change / len(input_text), error_rate=0.01)
elif i == 8:
##random_space_removal
input_text_process, num_change = random_space_removal(input_text_process, total_change / len(input_text), error_rate=0.01)
elif i == 9:
##remove_vietnamese_accents
input_text_process, num_change = remove_vietnamese_accents(input_text_process, total_change / len(input_text), error_rate=0.01)
total_change = total_change + num_change
print("Total change: ", total_change)
print("Tỷ lệ", total_change / len(input_text))
string_text_response = input_text_process
return str(string_text_response)
demo = gr.Interface(fn=final_result, inputs="textbox", outputs="textbox")
if __name__ == "__main__":
print(fomula.AP_fomula(error_rate=0.12))
demo.launch()
|