Spaces:
Sleeping
Sleeping
extract_text_from_image
Browse files
app.py
CHANGED
@@ -2269,6 +2269,16 @@ def download_content(content):
|
|
2269 |
word_path = create_word(content)
|
2270 |
return word_path
|
2271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2272 |
|
2273 |
# === INIT PARAMS ===
|
2274 |
def init_params(request: gr.Request):
|
@@ -3936,6 +3946,15 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3936 |
with gr.Row():
|
3937 |
with gr.Column():
|
3938 |
chinese_full_paragraph_input = gr.Textbox(label="輸入段落全文", lines=5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3939 |
with gr.Column():
|
3940 |
with gr.Row():
|
3941 |
chinese_full_paragraph_evaluate_button = gr.Button("段落全文分析", variant="primary")
|
@@ -3943,6 +3962,19 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
|
|
3943 |
chinese_full_paragraph_evaluate_output_text = gr.Markdown(label="段落全文分析")
|
3944 |
with gr.Row():
|
3945 |
chinese_full_paragraph_evaluate_output_table = gr.Dataframe(label="段落全文分析表格", wrap=True, column_widths=[20, 15, 65], interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3946 |
|
3947 |
# 修改文章
|
3948 |
with gr.Row():
|
|
|
2269 |
word_path = create_word(content)
|
2270 |
return word_path
|
2271 |
|
2272 |
+
# OCR
|
2273 |
+
def extract_text_from_image(image):
|
2274 |
+
"""從上傳的圖片中提取文字"""
|
2275 |
+
return "test"
|
2276 |
+
|
2277 |
+
# 使用 OCR 工具
|
2278 |
+
def extract_text_from_file(file):
|
2279 |
+
"""從上傳的文件中提取文字"""
|
2280 |
+
return "test"
|
2281 |
+
|
2282 |
|
2283 |
# === INIT PARAMS ===
|
2284 |
def init_params(request: gr.Request):
|
|
|
3946 |
with gr.Row():
|
3947 |
with gr.Column():
|
3948 |
chinese_full_paragraph_input = gr.Textbox(label="輸入段落全文", lines=5)
|
3949 |
+
with gr.Row():
|
3950 |
+
with gr.Column(scale=1):
|
3951 |
+
# 修正文件類型設置
|
3952 |
+
chinese_file_upload = gr.File(
|
3953 |
+
label="上傳文件",
|
3954 |
+
file_count="single" # 確保只能上傳一個文件
|
3955 |
+
)
|
3956 |
+
with gr.Column(scale=1):
|
3957 |
+
chinese_image_upload = gr.Image(label="上傳圖片或拍照", type="pil", sources=["upload", "webcam", "clipboard"])
|
3958 |
with gr.Column():
|
3959 |
with gr.Row():
|
3960 |
chinese_full_paragraph_evaluate_button = gr.Button("段落全文分析", variant="primary")
|
|
|
3962 |
chinese_full_paragraph_evaluate_output_text = gr.Markdown(label="段落全文分析")
|
3963 |
with gr.Row():
|
3964 |
chinese_full_paragraph_evaluate_output_table = gr.Dataframe(label="段落全文分析表格", wrap=True, column_widths=[20, 15, 65], interactive=False)
|
3965 |
+
|
3966 |
+
# 處理上傳文件和圖片的事件
|
3967 |
+
chinese_file_upload.change( # 使用 change 而不是 upload
|
3968 |
+
fn=extract_text_from_file,
|
3969 |
+
inputs=[chinese_file_upload],
|
3970 |
+
outputs=[chinese_full_paragraph_input]
|
3971 |
+
)
|
3972 |
+
|
3973 |
+
chinese_image_upload.change( # 使用 change 而不是 upload
|
3974 |
+
fn=extract_text_from_image,
|
3975 |
+
inputs=[chinese_image_upload],
|
3976 |
+
outputs=[chinese_full_paragraph_input]
|
3977 |
+
)
|
3978 |
|
3979 |
# 修改文章
|
3980 |
with gr.Row():
|