Update app.py
Browse files
app.py
CHANGED
|
@@ -33,22 +33,23 @@ def compare_texts(correct_file, wrong_file):
|
|
| 33 |
return correct_text_with_positions, wrong_text_with_positions, wrong_ids_str
|
| 34 |
|
| 35 |
def generate_json(file_id, correct_text, wrong_text, wrong_ids):
|
| 36 |
-
|
| 37 |
-
wrong_ids_list = [int(x) for x in wrong_ids.split(',')]
|
| 38 |
data = {
|
| 39 |
"id": file_id,
|
| 40 |
"original_text": wrong_text,
|
| 41 |
"wrong_ids": wrong_ids_list,
|
| 42 |
"correct_text": correct_text
|
| 43 |
}
|
|
|
|
| 44 |
json_data = json.dumps([data], ensure_ascii=False, indent=4)
|
| 45 |
-
|
| 46 |
-
#
|
| 47 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".json", mode='w', encoding='utf-8')
|
| 48 |
temp_file.write(json_data)
|
| 49 |
temp_file.close()
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
TITLE = """<h1>逐字稿文本內容比對工具</h1>"""
|
| 54 |
SUBTITLE = """<h2><a href='https://deep-learning-101.github.io' target='_blank'>deep-learning-101.github.io</a> | <a href='https://www.twman.org/AI' target='_blank'> AI </a> | <a href='https://www.twman.org' target='_blank'>TonTon Huang Ph.D.</a> | <a href='https://blog.twman.org/p/deeplearning101.html' target='_blank'>手把手帶你一起踩AI坑</a><br></h2>"""
|
|
|
|
| 33 |
return correct_text_with_positions, wrong_text_with_positions, wrong_ids_str
|
| 34 |
|
| 35 |
def generate_json(file_id, correct_text, wrong_text, wrong_ids):
|
| 36 |
+
wrong_ids_list = [int(x) for x in wrong_ids.split(',') if x.strip() != ""]
|
|
|
|
| 37 |
data = {
|
| 38 |
"id": file_id,
|
| 39 |
"original_text": wrong_text,
|
| 40 |
"wrong_ids": wrong_ids_list,
|
| 41 |
"correct_text": correct_text
|
| 42 |
}
|
| 43 |
+
|
| 44 |
json_data = json.dumps([data], ensure_ascii=False, indent=4)
|
| 45 |
+
|
| 46 |
+
# 產生暫存檔
|
| 47 |
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".json", mode='w', encoding='utf-8')
|
| 48 |
temp_file.write(json_data)
|
| 49 |
temp_file.close()
|
| 50 |
+
|
| 51 |
+
# Gradio File output 必須傳 tuple (path, filename)
|
| 52 |
+
return json_data, (temp_file.name, "output.json")
|
| 53 |
|
| 54 |
TITLE = """<h1>逐字稿文本內容比對工具</h1>"""
|
| 55 |
SUBTITLE = """<h2><a href='https://deep-learning-101.github.io' target='_blank'>deep-learning-101.github.io</a> | <a href='https://www.twman.org/AI' target='_blank'> AI </a> | <a href='https://www.twman.org' target='_blank'>TonTon Huang Ph.D.</a> | <a href='https://blog.twman.org/p/deeplearning101.html' target='_blank'>手把手帶你一起踩AI坑</a><br></h2>"""
|