mkaramb commited on
Commit
74d4646
·
verified ·
1 Parent(s): 5301308

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -5
app.py CHANGED
@@ -31,7 +31,6 @@ location = "us"
31
  processor_id = "4307b078717a399a"
32
 
33
  def translate_text(text, target_language="en"):
34
- logging.info(f"Translating text to {target_language}.")
35
  translate_client = translate.Client(credentials=credentials)
36
  result = translate_client.translate(text, target_language=target_language)
37
  return result["translatedText"]
@@ -40,14 +39,14 @@ def batch_process_documents(file_path: str, file_mime_type: str) -> tuple:
40
  logging.info(f"Processing document {file_path}.")
41
  opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com", credentials=credentials)
42
  client = documentai.DocumentProcessorServiceClient(client_options=opts)
43
-
44
  with open(file_path, "rb") as file_stream:
45
  raw_document = RawDocument(content=file_stream.read(), mime_type=file_mime_type)
46
 
47
  name = client.processor_path(project_id, location, processor_id)
48
  request = documentai.ProcessRequest(name=name, raw_document=raw_document)
49
  result = client.process_document(request=request)
50
-
51
  extracted_text = result.document.text
52
  translated_text = translate_text(extracted_text)
53
  logging.info(f"Document processed and translated for {file_path}.")
@@ -103,7 +102,7 @@ def process_images(uploaded_file):
103
 
104
  interface = gr.Interface(
105
  fn=process_images,
106
- inputs=gr.inputs.File(label="Upload ZIP File"),
107
  outputs="html",
108
  title="Document AI Translation",
109
  description="Upload a ZIP file containing JPEG/JPG images, and the system will extract and translate text from each image."
@@ -111,4 +110,3 @@ interface = gr.Interface(
111
 
112
  if __name__ == "__main__":
113
  interface.launch(debug=True)
114
-
 
31
  processor_id = "4307b078717a399a"
32
 
33
  def translate_text(text, target_language="en"):
 
34
  translate_client = translate.Client(credentials=credentials)
35
  result = translate_client.translate(text, target_language=target_language)
36
  return result["translatedText"]
 
39
  logging.info(f"Processing document {file_path}.")
40
  opts = ClientOptions(api_endpoint=f"{location}-documentai.googleapis.com", credentials=credentials)
41
  client = documentai.DocumentProcessorServiceClient(client_options=opts)
42
+
43
  with open(file_path, "rb") as file_stream:
44
  raw_document = RawDocument(content=file_stream.read(), mime_type=file_mime_type)
45
 
46
  name = client.processor_path(project_id, location, processor_id)
47
  request = documentai.ProcessRequest(name=name, raw_document=raw_document)
48
  result = client.process_document(request=request)
49
+
50
  extracted_text = result.document.text
51
  translated_text = translate_text(extracted_text)
52
  logging.info(f"Document processed and translated for {file_path}.")
 
102
 
103
  interface = gr.Interface(
104
  fn=process_images,
105
+ inputs=gr.components.File(label="Upload ZIP File"),
106
  outputs="html",
107
  title="Document AI Translation",
108
  description="Upload a ZIP file containing JPEG/JPG images, and the system will extract and translate text from each image."
 
110
 
111
  if __name__ == "__main__":
112
  interface.launch(debug=True)