File size: 1,231 Bytes
3180f51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import requests

WEBHOOK_URL = "https://hook.make.com/YOUR_WEBHOOK_URL"


def send_pdf(file):
    if file is None:
        return "❌ Please upload a PDF file."

    if not file.name.lower().endswith(".pdf"):
        return "❌ Only PDF files are allowed."

    try:
        with open(file.name, "rb") as f:
            response = requests.post(
                WEBHOOK_URL,
                files={"file": f},
                timeout=20
            )

        if response.status_code != 200:
            return "❌ Upload failed. Webhook returned an error."

        return "βœ… PDF sent successfully!"

    except Exception as e:
        return f"❌ Error sending file: {str(e)}"


with gr.Blocks(title="PDF Upload") as demo:
    gr.Markdown(
        """
        # πŸ“„ Upload PDF
        Select a PDF file and send it to the automation.
        """
    )

    pdf_input = gr.File(
        label="Choose PDF",
        file_types=[".pdf"],
        type="filepath"
    )

    send_button = gr.Button("Send File")
    status_output = gr.Markdown()

    send_button.click(
        fn=send_pdf,
        inputs=pdf_input,
        outputs=status_output
    )

demo.launch(server_name="0.0.0.0", server_port=7860)