Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -173,7 +173,7 @@ async def process_logs(file_obj, row_limit=10000, progress=gr.Progress()):
|
|
| 173 |
# Step 6: Dashboard Insights
|
| 174 |
insights = generate_dashboard_insights(df, progress)
|
| 175 |
|
| 176 |
-
#
|
| 177 |
latex_template = r"""
|
| 178 |
% Defining document class and basic setup
|
| 179 |
\documentclass[a4paper,10pt]{article}
|
|
@@ -270,5 +270,53 @@ The following table summarizes the usage hours for the top 5 devices:
|
|
| 270 |
latex_content = latex_content.replace("{{AMC_REMINDERS}}", "\n".join([f"\\item {line}" for line in reminder_lines]).replace("%", "\%"))
|
| 271 |
latex_content = latex_content.replace("{{DASHBOARD_INSIGHTS}}", insights.replace("%", "\%"))
|
| 272 |
|
| 273 |
-
#
|
| 274 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
# Step 6: Dashboard Insights
|
| 174 |
insights = generate_dashboard_insights(df, progress)
|
| 175 |
|
| 176 |
+
# Define the LaTeX template
|
| 177 |
latex_template = r"""
|
| 178 |
% Defining document class and basic setup
|
| 179 |
\documentclass[a4paper,10pt]{article}
|
|
|
|
| 270 |
latex_content = latex_content.replace("{{AMC_REMINDERS}}", "\n".join([f"\\item {line}" for line in reminder_lines]).replace("%", "\%"))
|
| 271 |
latex_content = latex_content.replace("{{DASHBOARD_INSIGHTS}}", insights.replace("%", "\%"))
|
| 272 |
|
| 273 |
+
# Construct the xaiArtifact tag with proper indentation
|
| 274 |
+
artifact_content = (
|
| 275 |
+
'<xaiArtifact artifact_id="05686e4a-85a8-4140-8113-1e86048b96fc" '
|
| 276 |
+
'artifact_version_id="48e949a0-ea29-45d9-b47d-7f21069da965" '
|
| 277 |
+
'title="LabOps_Analysis_Report.tex" contentType="text/latex">\n'
|
| 278 |
+
f'{latex_content}\n'
|
| 279 |
+
'</xaiArtifact>'
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
return artifact_content
|
| 283 |
+
|
| 284 |
+
except Exception as e:
|
| 285 |
+
logging.error(f"Failed to process file: {str(e)}")
|
| 286 |
+
return f"Failed to process file: {str(e)}"
|
| 287 |
+
|
| 288 |
+
# Gradio Interface
|
| 289 |
+
try:
|
| 290 |
+
logging.info("Initializing Gradio Blocks interface...")
|
| 291 |
+
with gr.Blocks() as iface:
|
| 292 |
+
gr.Markdown("<h1>LabOps Log Analyzer Dashboard (Hugging Face AI)</h1>")
|
| 293 |
+
gr.Markdown("Upload a CSV file to generate a PDF report.")
|
| 294 |
+
|
| 295 |
+
with gr.Row():
|
| 296 |
+
with gr.Column(scale=1):
|
| 297 |
+
file_input = gr.File(label="Upload Logs (CSV)", file_types=[".csv"])
|
| 298 |
+
submit_button = gr.Button("Generate PDF Report", variant="primary")
|
| 299 |
+
|
| 300 |
+
with gr.Column(scale=2):
|
| 301 |
+
output = gr.Markdown()
|
| 302 |
+
|
| 303 |
+
submit_button.click(
|
| 304 |
+
fn=process_logs,
|
| 305 |
+
inputs=[file_input],
|
| 306 |
+
outputs=[output]
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
logging.info("Gradio interface initialized successfully")
|
| 310 |
+
except Exception as e:
|
| 311 |
+
logging.error(f"Failed to initialize Gradio interface: {str(e)}")
|
| 312 |
+
raise e
|
| 313 |
+
|
| 314 |
+
if __name__ == "__main__":
|
| 315 |
+
try:
|
| 316 |
+
logging.info("Launching Gradio interface...")
|
| 317 |
+
iface.launch(server_name="0.0.0.0", server_port=7860, debug=True, share=False)
|
| 318 |
+
logging.info("Gradio interface launched successfully")
|
| 319 |
+
except Exception as e:
|
| 320 |
+
logging.error(f"Failed to launch Gradio interface: {str(e)}")
|
| 321 |
+
print(f"Error launching app: {str(e)}")
|
| 322 |
+
raise e
|