ShynBui's picture
update trong so
17eec93
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()