Spaces:
Running
Running
Commit
·
b077dda
1
Parent(s):
9051895
Make distribution plot larger with click-to-expand fullscreen
Browse files
app.py
CHANGED
|
@@ -1104,7 +1104,7 @@ Provide your work in JSON format where the number belonging to each category is
|
|
| 1104 |
pct = (count / total_rows) * 100 if total_rows > 0 else 0
|
| 1105 |
dist_data.append({"Category": cat, "Percentage": round(pct, 1)})
|
| 1106 |
|
| 1107 |
-
fig, ax = plt.subplots(figsize=(
|
| 1108 |
categories_list = [d["Category"] for d in dist_data][::-1]
|
| 1109 |
percentages = [d["Percentage"] for d in dist_data][::-1]
|
| 1110 |
|
|
@@ -1211,6 +1211,44 @@ custom_css = """
|
|
| 1211 |
min-width: 150px !important;
|
| 1212 |
}
|
| 1213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1214 |
/* Mobile-responsive styles */
|
| 1215 |
@media screen and (max-width: 768px) {
|
| 1216 |
/* Reduce overall padding */
|
|
@@ -1385,7 +1423,29 @@ custom_css = """
|
|
| 1385 |
}
|
| 1386 |
"""
|
| 1387 |
|
| 1388 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1389 |
gr.Image("logo.png", show_label=False, show_download_button=False, height=115, container=False)
|
| 1390 |
gr.Markdown("# CatLLM - Research Data Classifier")
|
| 1391 |
gr.Markdown("Extract categories from or classify text data, PDFs, and images using LLMs.")
|
|
@@ -1581,7 +1641,7 @@ Soria, C. (2025). CatLLM: A Python package for LLM-based text classification. DO
|
|
| 1581 |
# Classify output group
|
| 1582 |
with gr.Group(visible=False) as classify_output_group:
|
| 1583 |
gr.Markdown("### Classification Results")
|
| 1584 |
-
distribution_plot = gr.Plot(label="Category Distribution (%)", visible=False)
|
| 1585 |
results = gr.DataFrame(label="Full Results", visible=False)
|
| 1586 |
download_file = gr.File(label="Download Results (CSV + Methodology Report)", file_count="multiple")
|
| 1587 |
with gr.Accordion("See the Code", open=False):
|
|
|
|
| 1104 |
pct = (count / total_rows) * 100 if total_rows > 0 else 0
|
| 1105 |
dist_data.append({"Category": cat, "Percentage": round(pct, 1)})
|
| 1106 |
|
| 1107 |
+
fig, ax = plt.subplots(figsize=(12, max(6, len(dist_data) * 1.0)))
|
| 1108 |
categories_list = [d["Category"] for d in dist_data][::-1]
|
| 1109 |
percentages = [d["Percentage"] for d in dist_data][::-1]
|
| 1110 |
|
|
|
|
| 1211 |
min-width: 150px !important;
|
| 1212 |
}
|
| 1213 |
|
| 1214 |
+
/* Expandable plot styles */
|
| 1215 |
+
.expandable-plot {
|
| 1216 |
+
min-height: 400px !important;
|
| 1217 |
+
cursor: pointer;
|
| 1218 |
+
transition: transform 0.3s ease;
|
| 1219 |
+
}
|
| 1220 |
+
|
| 1221 |
+
.expandable-plot:hover {
|
| 1222 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
| 1223 |
+
}
|
| 1224 |
+
|
| 1225 |
+
.expandable-plot img {
|
| 1226 |
+
min-height: 350px !important;
|
| 1227 |
+
object-fit: contain;
|
| 1228 |
+
}
|
| 1229 |
+
|
| 1230 |
+
/* Fullscreen modal for plot */
|
| 1231 |
+
.expandable-plot.fullscreen {
|
| 1232 |
+
position: fixed !important;
|
| 1233 |
+
top: 0 !important;
|
| 1234 |
+
left: 0 !important;
|
| 1235 |
+
width: 100vw !important;
|
| 1236 |
+
height: 100vh !important;
|
| 1237 |
+
z-index: 9999 !important;
|
| 1238 |
+
background: rgba(255, 255, 255, 0.98) !important;
|
| 1239 |
+
padding: 20px !important;
|
| 1240 |
+
margin: 0 !important;
|
| 1241 |
+
display: flex !important;
|
| 1242 |
+
align-items: center !important;
|
| 1243 |
+
justify-content: center !important;
|
| 1244 |
+
}
|
| 1245 |
+
|
| 1246 |
+
.expandable-plot.fullscreen img {
|
| 1247 |
+
max-width: 95vw !important;
|
| 1248 |
+
max-height: 90vh !important;
|
| 1249 |
+
min-height: auto !important;
|
| 1250 |
+
}
|
| 1251 |
+
|
| 1252 |
/* Mobile-responsive styles */
|
| 1253 |
@media screen and (max-width: 768px) {
|
| 1254 |
/* Reduce overall padding */
|
|
|
|
| 1423 |
}
|
| 1424 |
"""
|
| 1425 |
|
| 1426 |
+
custom_js = """
|
| 1427 |
+
function() {
|
| 1428 |
+
// Add click-to-expand functionality for the plot
|
| 1429 |
+
document.addEventListener('click', function(e) {
|
| 1430 |
+
const plot = e.target.closest('.expandable-plot');
|
| 1431 |
+
if (plot) {
|
| 1432 |
+
plot.classList.toggle('fullscreen');
|
| 1433 |
+
}
|
| 1434 |
+
});
|
| 1435 |
+
|
| 1436 |
+
// Close fullscreen on Escape key
|
| 1437 |
+
document.addEventListener('keydown', function(e) {
|
| 1438 |
+
if (e.key === 'Escape') {
|
| 1439 |
+
const fullscreenPlot = document.querySelector('.expandable-plot.fullscreen');
|
| 1440 |
+
if (fullscreenPlot) {
|
| 1441 |
+
fullscreenPlot.classList.remove('fullscreen');
|
| 1442 |
+
}
|
| 1443 |
+
}
|
| 1444 |
+
});
|
| 1445 |
+
}
|
| 1446 |
+
"""
|
| 1447 |
+
|
| 1448 |
+
with gr.Blocks(title="CatLLM - Research Data Classifier", theme=gr.themes.Soft(), css=custom_css, js=custom_js) as demo:
|
| 1449 |
gr.Image("logo.png", show_label=False, show_download_button=False, height=115, container=False)
|
| 1450 |
gr.Markdown("# CatLLM - Research Data Classifier")
|
| 1451 |
gr.Markdown("Extract categories from or classify text data, PDFs, and images using LLMs.")
|
|
|
|
| 1641 |
# Classify output group
|
| 1642 |
with gr.Group(visible=False) as classify_output_group:
|
| 1643 |
gr.Markdown("### Classification Results")
|
| 1644 |
+
distribution_plot = gr.Plot(label="Category Distribution (%)", visible=False, elem_classes="expandable-plot")
|
| 1645 |
results = gr.DataFrame(label="Full Results", visible=False)
|
| 1646 |
download_file = gr.File(label="Download Results (CSV + Methodology Report)", file_count="multiple")
|
| 1647 |
with gr.Accordion("See the Code", open=False):
|