File size: 1,451 Bytes
479c5b5
d1c6587
ebf808d
479c5b5
d1c6587
 
 
 
 
 
 
 
 
 
 
ebf808d
 
 
 
 
 
 
 
 
 
 
 
d1c6587
 
 
 
 
 
 
 
 
 
 
479c5b5
 
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
import gradio as gr
import subprocess
import json

def api_call(input_text):
    # Replace 'YOUR_CURL_COMMAND' with the actual cURL command you want to use
    curl_command = [
        'curl', '-s', '--request', 'GET',
        '--url', f"https://api.padlet.dev/v1/boards/{input_text}?include=posts%2Csections",
        '--header', 'X-Api-Key: pdltp_0e380a0de1ff32d77b12dbcc030b1373199b7525681ddc81bd1b9ef3e4e3dd49577a23',
        '--header', 'accept: application/vnd.api+json'
    ]
    
    try:
        response = subprocess.check_output(curl_command, universal_newlines=True)
        response_data = json.loads(response)
        
        # Extract the contents of all posts
        posts_data = response_data.get("included", [])
        post_contents = []
        for post in posts_data:
            if post.get("type") == "post":
                content = post.get("attributes", {}).get("content", {}).get("subject", "")
                if content:
                    post_contents.append(content)
        
        return "\n".join(post_contents) if post_contents else "No post contents found."
    except subprocess.CalledProcessError:
        return "Error: Unable to fetch data using cURL."

iface = gr.Interface(
    fn=api_call,
    inputs=gr.inputs.Textbox(),
    outputs=gr.outputs.Textbox(),
    live=True,
    title="Padlet API Caller with cURL",
    description="Enter Padlet board ID and get board details using cURL"
)

iface.launch()