youngtsai commited on
Commit
63cc718
·
1 Parent(s): 979dcbd

chinese_image_url_input = gr.Textbox(label="輸入圖片網址")

Browse files
Files changed (1) hide show
  1. app.py +15 -1
app.py CHANGED
@@ -2293,7 +2293,10 @@ def extract_text_from_image(image_input):
2293
  elif isinstance(image_input, str):
2294
  if image_input.startswith("http"):
2295
  # 網路圖片
2296
- response = requests.get(image_input)
 
 
 
2297
  image = Image.open(io.BytesIO(response.content)).convert("RGB")
2298
  elif image_input.startswith("data:image"):
2299
  # base64 with header
@@ -4050,6 +4053,11 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
4050
  with gr.Row():
4051
  with gr.Column(scale=1):
4052
  chinese_image_upload = gr.Image(label="上傳圖片或拍照", type="pil", sources=["upload", "webcam", "clipboard"])
 
 
 
 
 
4053
  with gr.Column():
4054
  with gr.Row():
4055
  chinese_full_paragraph_evaluate_button = gr.Button("段落全文分析", variant="primary")
@@ -4064,6 +4072,12 @@ with gr.Blocks(theme=THEME, css=CSS) as demo:
4064
  outputs=[chinese_full_paragraph_input]
4065
  )
4066
 
 
 
 
 
 
 
4067
  # 修改文章
4068
  with gr.Row():
4069
  gr.Markdown("# 根據建議修改文章")
 
2293
  elif isinstance(image_input, str):
2294
  if image_input.startswith("http"):
2295
  # 網路圖片
2296
+ headers = {
2297
+ "User-Agent": "Mozilla/5.0"
2298
+ }
2299
+ response = requests.get(image_input, headers=headers)
2300
  image = Image.open(io.BytesIO(response.content)).convert("RGB")
2301
  elif image_input.startswith("data:image"):
2302
  # base64 with header
 
4053
  with gr.Row():
4054
  with gr.Column(scale=1):
4055
  chinese_image_upload = gr.Image(label="上傳圖片或拍照", type="pil", sources=["upload", "webcam", "clipboard"])
4056
+ with gr.Row():
4057
+ with gr.Column(scale=1):
4058
+ chinese_image_url_input = gr.Textbox(label="輸入圖片網址")
4059
+ with gr.Column(scale=1):
4060
+ chinese_image_url_input_button = gr.Button("👉 取得圖片文字", variant="primary")
4061
  with gr.Column():
4062
  with gr.Row():
4063
  chinese_full_paragraph_evaluate_button = gr.Button("段落全文分析", variant="primary")
 
4072
  outputs=[chinese_full_paragraph_input]
4073
  )
4074
 
4075
+ chinese_image_url_input_button.click(
4076
+ fn=extract_text_from_image,
4077
+ inputs=[chinese_image_url_input],
4078
+ outputs=[chinese_full_paragraph_input]
4079
+ )
4080
+
4081
  # 修改文章
4082
  with gr.Row():
4083
  gr.Markdown("# 根據建議修改文章")