internationalscholarsprogram commited on
Commit
928c304
·
1 Parent(s): 3511fa6

Add application file

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from docx import Document # from python-docx
4
+
5
+ def docx_to_json(file_obj):
6
+ if file_obj is None:
7
+ return "No file uploaded", "{}"
8
+
9
+ # Load docx
10
+ document = Document(file_obj.name)
11
+
12
+ # Very simple example: collect paragraphs as a list
13
+ paragraphs = [p.text for p in document.paragraphs if p.text.strip() != ""]
14
+
15
+ # Build a JSON structure (customize to your needs)
16
+ data = {
17
+ "paragraphs": paragraphs,
18
+ "paragraph_count": len(paragraphs),
19
+ }
20
+
21
+ return json.dumps(data, indent=2)
22
+
23
+ with gr.Blocks() as demo:
24
+ gr.Markdown("# DOCX → JSON & DB Sync (Prototype)")
25
+
26
+ with gr.Row():
27
+ file_input = gr.File(label="Upload Word (.docx)")
28
+
29
+ json_output = gr.Code(label="Extracted JSON", language="json")
30
+
31
+ btn = gr.Button("Convert to JSON")
32
+
33
+ btn.click(fn=docx_to_json, inputs=file_input, outputs=json_output)
34
+
35
+ if __name__ == "__main__":
36
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ python-docx
3
+ deepdiff
4
+ mysql-connector-python # or psycopg2 / sqlalchemy depending on your DB