IvanMiao commited on
Commit
676dc22
·
1 Parent(s): bb303c8

fix: File object

Browse files
Files changed (2) hide show
  1. app.py +3 -2
  2. process/ocr.py +2 -2
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import gradio as gr
 
2
  from process.ocr import perform_raw_ocr, correct_text_with_ai
3
  from process.interpretation import get_interpretation
4
  from process.translation import get_translaton
@@ -28,7 +29,7 @@ def update_api_keys(mistral_key, gemini_key):
28
  return "API keys saved"
29
 
30
 
31
- def ocr_workflow_wrapper(file, mistral_key):
32
  """
33
  Manages the OCR workflow, processing an uploaded file to extract text.
34
 
@@ -43,7 +44,7 @@ def ocr_workflow_wrapper(file, mistral_key):
43
  error_msg = "Error: Mistral API Key not set."
44
  yield error_msg, error_msg
45
  return
46
- if not file:
47
  error_msg = "Error: File/Text not found."
48
  yield error_msg, error_msg
49
  return
 
1
  import gradio as gr
2
+ from gradio import File
3
  from process.ocr import perform_raw_ocr, correct_text_with_ai
4
  from process.interpretation import get_interpretation
5
  from process.translation import get_translaton
 
29
  return "API keys saved"
30
 
31
 
32
+ def ocr_workflow_wrapper(file: File, mistral_key: str):
33
  """
34
  Manages the OCR workflow, processing an uploaded file to extract text.
35
 
 
44
  error_msg = "Error: Mistral API Key not set."
45
  yield error_msg, error_msg
46
  return
47
+ if not file or file.name == "":
48
  error_msg = "Error: File/Text not found."
49
  yield error_msg, error_msg
50
  return
process/ocr.py CHANGED
@@ -1,6 +1,6 @@
1
  from mistralai import Mistral
2
  from mistralai.models import OCRResponse
3
-
4
 
5
  OCR_MODEL = "mistral-ocr-latest"
6
  CHAT_MODEL = "mistral-large-latest"
@@ -94,7 +94,7 @@ def correct_text_with_ai(text: str, api_key: str) -> str:
94
  return(response.choices[0].message.content)
95
 
96
 
97
- def perform_raw_ocr(input_file, api_key: str):
98
  if input_file != None:
99
  file_ext = input_file.name.split('.')[-1].lower()
100
  else:
 
1
  from mistralai import Mistral
2
  from mistralai.models import OCRResponse
3
+ from gradio import File
4
 
5
  OCR_MODEL = "mistral-ocr-latest"
6
  CHAT_MODEL = "mistral-large-latest"
 
94
  return(response.choices[0].message.content)
95
 
96
 
97
+ def perform_raw_ocr(input_file: File, api_key: str):
98
  if input_file != None:
99
  file_ext = input_file.name.split('.')[-1].lower()
100
  else: