Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
# Sanity project details
|
| 6 |
+
project_id = st.secrets["project_id"] # You can store secrets in Hugging Face Spaces
|
| 7 |
+
dataset = st.secrets["dataset"] # Store your dataset name as a secret
|
| 8 |
+
token = st.secrets["api_token"] # Store your API token as a secret
|
| 9 |
+
|
| 10 |
+
# Sanity API URL for querying tasks
|
| 11 |
+
url = f'https://{project_id}.api.sanity.io/v1/data/query/{dataset}'
|
| 12 |
+
|
| 13 |
+
# GROQ query to get tasks
|
| 14 |
+
groq_query = """
|
| 15 |
+
*[_type == "task"]{
|
| 16 |
+
_id,
|
| 17 |
+
title,
|
| 18 |
+
description,
|
| 19 |
+
status,
|
| 20 |
+
dueDate
|
| 21 |
+
}
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
# Prepare headers with authorization token
|
| 25 |
+
headers = {
|
| 26 |
+
'Authorization': f'Bearer {token}'
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
# Streamlit UI elements
|
| 30 |
+
st.title('Sanity Task Dashboard')
|
| 31 |
+
st.write('This is a task dashboard fetching data from Sanity CMS.')
|
| 32 |
+
|
| 33 |
+
# Fetch data using the GROQ query
|
| 34 |
+
response = requests.get(url, headers=headers, params={'query': groq_query})
|
| 35 |
+
|
| 36 |
+
# Check if request was successful
|
| 37 |
+
if response.status_code == 200:
|
| 38 |
+
tasks = response.json()['result'] # Get tasks from the response
|
| 39 |
+
tasks_df = pd.DataFrame(tasks) # Create a DataFrame from the tasks
|
| 40 |
+
tasks_df['dueDate'] = pd.to_datetime(tasks_df['dueDate']) # Convert 'dueDate' to datetime
|
| 41 |
+
|
| 42 |
+
st.dataframe(tasks_df) # Display the tasks in a table
|
| 43 |
+
else:
|
| 44 |
+
st.error(f"Error fetching tasks: {response.status_code} - {response.text}")
|