yasserrmd commited on
Commit
4678d36
·
verified ·
1 Parent(s): 8e94e51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -1,15 +1,14 @@
1
  import gradio as gr
2
  from docling.document_converter import DocumentConverter
3
- import spaces
4
 
5
-
6
-
7
- @spaces.GPU
8
  def convert_document(file, output_format):
9
  # Load document and convert it using Docling
10
  converter = DocumentConverter()
11
  result = converter.convert(file.name)
12
-
 
 
 
13
  # Choose the output format
14
  if output_format == "Markdown":
15
  converted_text = result.document.export_to_markdown()
@@ -18,17 +17,14 @@ def convert_document(file, output_format):
18
  else:
19
  converted_text = "Unsupported format"
20
 
21
- # Extract metadata
22
  metadata = {
23
- "Title": result.document.title,
24
- "Author": result.document.author,
25
- "Language": result.document.language,
26
- "References": result.document.references
27
  }
28
 
29
  return converted_text, metadata
30
 
31
- # Define the Gradio interface using new component syntax
32
  with gr.Blocks() as app:
33
  gr.Markdown("# Document Converter with Docling")
34
  gr.Markdown("Upload a document, choose the output format, and get the converted text with metadata.")
 
1
  import gradio as gr
2
  from docling.document_converter import DocumentConverter
 
3
 
 
 
 
4
  def convert_document(file, output_format):
5
  # Load document and convert it using Docling
6
  converter = DocumentConverter()
7
  result = converter.convert(file.name)
8
+
9
+ # Check available attributes in DoclingDocument
10
+ available_attributes = dir(result.document)
11
+
12
  # Choose the output format
13
  if output_format == "Markdown":
14
  converted_text = result.document.export_to_markdown()
 
17
  else:
18
  converted_text = "Unsupported format"
19
 
20
+ # Placeholder metadata extraction based on available attributes
21
  metadata = {
22
+ "Available Attributes": available_attributes
 
 
 
23
  }
24
 
25
  return converted_text, metadata
26
 
27
+ # Define the Gradio interface using the new component syntax
28
  with gr.Blocks() as app:
29
  gr.Markdown("# Document Converter with Docling")
30
  gr.Markdown("Upload a document, choose the output format, and get the converted text with metadata.")