Threscomma commited on
Commit
b7aaaf5
·
verified ·
1 Parent(s): 2017b8a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from syncfusion import DocToImageConverter
3
+ import tempfile
4
+ import os
5
+
6
+ def convert_word_to_image(word_file):
7
+ # Save the uploaded file temporarily
8
+ temp_dir = tempfile.mkdtemp()
9
+ input_path = os.path.join(temp_dir, word_file.name)
10
+ with open(input_path, "wb") as f:
11
+ f.write(word_file.read())
12
+
13
+ # Convert Word to Image
14
+ converter = DocToImageConverter()
15
+ output_images = converter.convert_to_images(input_path)
16
+
17
+ # Return the first image (or handle multiple)
18
+ return output_images[0] if output_images else None
19
+
20
+ # Gradio Interface
21
+ iface = gr.Interface(
22
+ fn=convert_word_to_image,
23
+ inputs=gr.File(label="📄 Upload Word Document (DOCX)"),
24
+ outputs=gr.Image(label="🖼️ Converted Image"),
25
+ title="Word to Image Converter",
26
+ description="Upload a Word file (DOCX) to convert it to an image."
27
+ )
28
+
29
+ iface.launch()