Sahanabg commited on
Commit
3180f51
Β·
verified Β·
1 Parent(s): 161d9c8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ WEBHOOK_URL = "https://hook.make.com/YOUR_WEBHOOK_URL"
5
+
6
+
7
+ def send_pdf(file):
8
+ if file is None:
9
+ return "❌ Please upload a PDF file."
10
+
11
+ if not file.name.lower().endswith(".pdf"):
12
+ return "❌ Only PDF files are allowed."
13
+
14
+ try:
15
+ with open(file.name, "rb") as f:
16
+ response = requests.post(
17
+ WEBHOOK_URL,
18
+ files={"file": f},
19
+ timeout=20
20
+ )
21
+
22
+ if response.status_code != 200:
23
+ return "❌ Upload failed. Webhook returned an error."
24
+
25
+ return "βœ… PDF sent successfully!"
26
+
27
+ except Exception as e:
28
+ return f"❌ Error sending file: {str(e)}"
29
+
30
+
31
+ with gr.Blocks(title="PDF Upload") as demo:
32
+ gr.Markdown(
33
+ """
34
+ # πŸ“„ Upload PDF
35
+ Select a PDF file and send it to the automation.
36
+ """
37
+ )
38
+
39
+ pdf_input = gr.File(
40
+ label="Choose PDF",
41
+ file_types=[".pdf"],
42
+ type="filepath"
43
+ )
44
+
45
+ send_button = gr.Button("Send File")
46
+ status_output = gr.Markdown()
47
+
48
+ send_button.click(
49
+ fn=send_pdf,
50
+ inputs=pdf_input,
51
+ outputs=status_output
52
+ )
53
+
54
+ demo.launch(server_name="0.0.0.0", server_port=7860)