Spaces:
Configuration error
Configuration error
Update index.html
Browse files- index.html +151 -56
index.html
CHANGED
|
@@ -1,58 +1,153 @@
|
|
|
|
|
| 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 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import requests
|
| 6 |
+
from bs4 import BeautifulSoup
|
| 7 |
+
from transformers import pipeline
|
| 8 |
+
|
| 9 |
+
# --- Backend Functions ---
|
| 10 |
+
|
| 11 |
+
# 1. Function for the WCAG Checker Tab
|
| 12 |
+
def check_accessibility(url):
|
| 13 |
+
"""
|
| 14 |
+
Performs a very basic accessibility check on a given URL.
|
| 15 |
+
This is a simplified example.
|
| 16 |
+
"""
|
| 17 |
+
if not url.startswith('http'):
|
| 18 |
+
url = 'https://' + url
|
| 19 |
+
try:
|
| 20 |
+
response = requests.get(url, timeout=10)
|
| 21 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 22 |
+
|
| 23 |
+
results = []
|
| 24 |
+
# Check 1: Document language
|
| 25 |
+
if soup.html and soup.html.get('lang'):
|
| 26 |
+
results.append("β
HTML 'lang' attribute is present.")
|
| 27 |
+
else:
|
| 28 |
+
results.append("β HTML 'lang' attribute is missing. This is important for screen readers.")
|
| 29 |
+
|
| 30 |
+
# Check 2: Image alt text
|
| 31 |
+
images_without_alt = [img for img in soup.find_all('img') if not img.get('alt', '').strip()]
|
| 32 |
+
if not images_without_alt:
|
| 33 |
+
results.append("β
All <img> tags seem to have 'alt' attributes.")
|
| 34 |
+
else:
|
| 35 |
+
results.append(f"β Found {len(images_without_alt)} <img> tags missing descriptive 'alt' text.")
|
| 36 |
+
|
| 37 |
+
# Check 3: Page Title
|
| 38 |
+
if soup.title and soup.title.string:
|
| 39 |
+
results.append(f"β
Page has a title: '{soup.title.string.strip()}'")
|
| 40 |
+
else:
|
| 41 |
+
results.append("β Page is missing a <title> tag.")
|
| 42 |
+
|
| 43 |
+
return "\n".join(results)
|
| 44 |
+
|
| 45 |
+
except requests.RequestException as e:
|
| 46 |
+
return f"Error: Could not fetch the URL. Please check the address. Details: {e}"
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"An unexpected error occurred: {e}"
|
| 49 |
+
|
| 50 |
+
# 2. Functions for the Data Explorer Tab
|
| 51 |
+
# Let's create some sample data to represent your projects.
|
| 52 |
+
# In a real-world scenario, you would upload these as CSV files to your Space.
|
| 53 |
+
|
| 54 |
+
# Mock Data for 'ssa-death-stats'
|
| 55 |
+
ssa_data = {
|
| 56 |
+
'Year': [2020, 2021, 2022],
|
| 57 |
+
'Total Deaths (Millions)': [3.3, 3.4, 3.2],
|
| 58 |
+
'Cause': ['Various', 'Various', 'Various']
|
| 59 |
}
|
| 60 |
+
df_ssa = pd.DataFrame(ssa_data)
|
| 61 |
+
|
| 62 |
+
# Mock Data for 'add-ssdi'
|
| 63 |
+
add_ssdi_data = {
|
| 64 |
+
'Fiscal Year': [2021, 2022],
|
| 65 |
+
'Applications (Thousands)': [1950, 1870],
|
| 66 |
+
'Initial Claims with ADD Diagnosis': [78000, 81000]
|
| 67 |
+
}
|
| 68 |
+
df_add_ssdi = pd.DataFrame(add_ssdi_data)
|
| 69 |
+
|
| 70 |
+
datasets = {
|
| 71 |
+
"SSA Death Statistics": df_ssa,
|
| 72 |
+
"ADD & SSDI Claims": df_add_ssdi,
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
def get_dataset(dataset_name):
|
| 76 |
+
"""Returns the selected pandas DataFrame."""
|
| 77 |
+
return datasets.get(dataset_name, pd.DataFrame())
|
| 78 |
+
|
| 79 |
+
# 3. Function for the AI Chat Tab
|
| 80 |
+
# Using a simple conversational pipeline from Hugging Face
|
| 81 |
+
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
|
| 82 |
+
|
| 83 |
+
def chat_with_ai(message, history):
|
| 84 |
+
"""
|
| 85 |
+
Takes user message and conversation history, returns AI response.
|
| 86 |
+
"""
|
| 87 |
+
history = history or []
|
| 88 |
+
response = chatbot(message, history)
|
| 89 |
+
# The pipeline returns a Conversation object, we need to extract the response
|
| 90 |
+
# This part might need adjustment based on the exact pipeline version
|
| 91 |
+
if hasattr(response, 'generated_responses'):
|
| 92 |
+
# For newer versions
|
| 93 |
+
new_response = response.generated_responses[-1]
|
| 94 |
+
else:
|
| 95 |
+
# Fallback for older structures
|
| 96 |
+
new_response = response.conversation_history[-1]
|
| 97 |
+
|
| 98 |
+
history.append((message, new_response))
|
| 99 |
+
return "", history
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
# --- Gradio UI ---
|
| 103 |
+
|
| 104 |
+
with gr.Blocks(theme=gr.themes.Soft(), css="footer {visibility: hidden}") as demo:
|
| 105 |
+
gr.Markdown("# π€ Consolidated AI & Data Hub for Disability Justice")
|
| 106 |
+
gr.Markdown("An integrated platform combining accessibility tools, data insights, and AI assistance.")
|
| 107 |
+
|
| 108 |
+
with gr.Tab("π Home"):
|
| 109 |
+
gr.Markdown(
|
| 110 |
+
"""
|
| 111 |
+
## Welcome!
|
| 112 |
+
This application brings together several tools and datasets focused on accessibility and disability justice.
|
| 113 |
+
|
| 114 |
+
Navigate through the tabs to explore:
|
| 115 |
+
- **WCAG Checker:** A simple tool to analyze web accessibility.
|
| 116 |
+
- **Disability Data Explorer:** View data related to Social Security and disability claims.
|
| 117 |
+
- **AI for Disability Justice:** An AI assistant to answer your questions.
|
| 118 |
+
|
| 119 |
+
*This is a demonstration project created by `caustino`.*
|
| 120 |
+
"""
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
with gr.Tab("βΏ WCAG Checker"):
|
| 124 |
+
gr.Markdown("### Basic Web Accessibility (WCAG) Checker")
|
| 125 |
+
gr.Markdown("Enter a website URL to perform a few basic accessibility checks.")
|
| 126 |
+
with gr.Row():
|
| 127 |
+
url_input = gr.Textbox(label="Website URL", placeholder="e.g., example.com")
|
| 128 |
+
check_button = gr.Button("Analyze Site", variant="primary")
|
| 129 |
+
output_text = gr.Textbox(label="Analysis Results", lines=8, interactive=False)
|
| 130 |
+
|
| 131 |
+
check_button.click(fn=check_accessibility, inputs=url_input, outputs=output_text)
|
| 132 |
+
|
| 133 |
+
with gr.Tab("π Disability Data Explorer"):
|
| 134 |
+
gr.Markdown("### Explore Disability-Related Datasets")
|
| 135 |
+
gr.Markdown("Select a dataset from the dropdown to view its contents.")
|
| 136 |
+
dataset_dropdown = gr.Dropdown(choices=list(datasets.keys()), label="Select Dataset")
|
| 137 |
+
data_frame_output = gr.DataFrame(label="Dataset")
|
| 138 |
+
|
| 139 |
+
dataset_dropdown.change(fn=get_dataset, inputs=dataset_dropdown, outputs=data_frame_output)
|
| 140 |
+
|
| 141 |
+
with gr.Tab("π¬ AI for Disability Justice"):
|
| 142 |
+
gr.Markdown("### AI Assistant")
|
| 143 |
+
gr.Markdown("Ask questions about disability rights, accessibility, or the data presented in this hub.")
|
| 144 |
+
chatbot_ui = gr.Chatbot(label="Conversation")
|
| 145 |
+
msg_input = gr.Textbox(label="Your Message", placeholder="Type your question here and press Enter...")
|
| 146 |
+
clear_button = gr.Button("Clear Chat")
|
| 147 |
+
|
| 148 |
+
msg_input.submit(fn=chat_with_ai, inputs=[msg_input, chatbot_ui], outputs=[msg_input, chatbot_ui])
|
| 149 |
+
clear_button.click(lambda: None, None, chatbot_ui, queue=False)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
# Launch the application
|
| 153 |
+
demo.launch()
|