Spaces:
Runtime error
Runtime error
feature: just show posts
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
|
|
3 |
|
4 |
def api_call(input_text):
|
5 |
# Replace 'YOUR_CURL_COMMAND' with the actual cURL command you want to use
|
@@ -12,7 +13,18 @@ def api_call(input_text):
|
|
12 |
|
13 |
try:
|
14 |
response = subprocess.check_output(curl_command, universal_newlines=True)
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
except subprocess.CalledProcessError:
|
17 |
return "Error: Unable to fetch data using cURL."
|
18 |
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
+
import json
|
4 |
|
5 |
def api_call(input_text):
|
6 |
# Replace 'YOUR_CURL_COMMAND' with the actual cURL command you want to use
|
|
|
13 |
|
14 |
try:
|
15 |
response = subprocess.check_output(curl_command, universal_newlines=True)
|
16 |
+
response_data = json.loads(response)
|
17 |
+
|
18 |
+
# Extract the contents of all posts
|
19 |
+
posts_data = response_data.get("included", [])
|
20 |
+
post_contents = []
|
21 |
+
for post in posts_data:
|
22 |
+
if post.get("type") == "post":
|
23 |
+
content = post.get("attributes", {}).get("content", {}).get("subject", "")
|
24 |
+
if content:
|
25 |
+
post_contents.append(content)
|
26 |
+
|
27 |
+
return "\n".join(post_contents) if post_contents else "No post contents found."
|
28 |
except subprocess.CalledProcessError:
|
29 |
return "Error: Unable to fetch data using cURL."
|
30 |
|