psujay commited on
Commit
5a49107
·
verified ·
1 Parent(s): 0e93bc7

Upload gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +50 -0
gradio_app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ BASE_URL = "https://citegraph-1099254244451.us-east1.run.app/"
5
+ HEADERS = {"Content-Type": "application/json"}
6
+
7
+
8
+ def load_documents(file_path):
9
+ print(file_path)
10
+ url = f"{BASE_URL}/api/predict"
11
+ if file_path is not None:
12
+ with open(file_path.name, "rb") as f:
13
+ file = {"file": f}
14
+ response = requests.post(url, files=file)
15
+ f.close()
16
+
17
+ output = response.json()
18
+ print(output)
19
+ return f"## Output: \n# <div align='center'>{output['predicted_label']}</div>"
20
+
21
+
22
+ def createUI():
23
+ css = """
24
+ h1 {
25
+ text-align: center;
26
+ display:block;
27
+ }
28
+ """
29
+ with gr.Blocks(css=css) as demo:
30
+ with gr.Row():
31
+ with gr.Column(scale=1):
32
+ # pdf_display = gr.Image(
33
+ # label="Uploaded PDF Page", interactive=False, height=680
34
+ # )
35
+ upload_btn = gr.File(label="Upload a PDF", file_types=[".pdf"])
36
+
37
+ with gr.Row():
38
+ class_label = gr.Markdown("## Output: ")
39
+
40
+ upload_btn.upload(
41
+ fn=load_documents,
42
+ inputs=[upload_btn],
43
+ outputs=[class_label],
44
+ )
45
+ return demo
46
+
47
+
48
+ if __name__ == "__main__":
49
+ demo = createUI()
50
+ demo.launch(pwa=True, share=False)