|
|
|
|
|
|
|
|
|
|
|
import gradio as gr |
|
|
from app import read_file, analyze_data, generate_visualizations, display_analysis |
|
|
|
|
|
def simple_process_file(file): |
|
|
"""Simplified version without AI models for testing""" |
|
|
|
|
|
df = read_file(file) |
|
|
|
|
|
if isinstance(df, str): |
|
|
return df, None, None, None |
|
|
|
|
|
|
|
|
analysis = analyze_data(df) |
|
|
|
|
|
|
|
|
visualizations = generate_visualizations(df) |
|
|
|
|
|
|
|
|
cleaning_recommendations = """ |
|
|
## Data Cleaning Recommendations |
|
|
|
|
|
* Handle missing values by either removing rows or imputing with mean/median/mode |
|
|
* Remove duplicate rows if present |
|
|
* Convert date-like string columns to proper datetime format |
|
|
* Standardize text data by removing extra spaces and converting to lowercase |
|
|
* Check for and handle outliers in numerical columns |
|
|
|
|
|
Note: This is a demo recommendation (AI model not connected in demo mode) |
|
|
""" |
|
|
|
|
|
|
|
|
analysis_insights = """ |
|
|
## Data Analysis Insights |
|
|
|
|
|
1. Examine the distribution of each numeric column |
|
|
2. Analyze correlations between numeric features |
|
|
3. Look for patterns in categorical data |
|
|
4. Consider creating visualizations like histograms and scatter plots |
|
|
5. Explore relationships between different variables |
|
|
|
|
|
Note: This is a demo insight (AI model not connected in demo mode) |
|
|
""" |
|
|
|
|
|
return analysis, visualizations, cleaning_recommendations, analysis_insights |
|
|
|
|
|
def demo_ui(file): |
|
|
"""Demo mode UI function""" |
|
|
if file is None: |
|
|
return "Please upload a file to begin analysis.", None, None, None |
|
|
|
|
|
|
|
|
analysis, visualizations, cleaning_recommendations, analysis_insights = simple_process_file(file) |
|
|
|
|
|
|
|
|
analysis_html = display_analysis(analysis) |
|
|
|
|
|
|
|
|
viz_html = "" |
|
|
if visualizations and not isinstance(visualizations, str): |
|
|
for viz_name, fig in visualizations.items(): |
|
|
|
|
|
viz_html += f'<div style="margin-bottom: 30px;">{fig.to_html(full_html=False, include_plotlyjs="cdn")}</div>' |
|
|
|
|
|
|
|
|
result_html = f""" |
|
|
<div style="display: flex; flex-direction: column;"> |
|
|
<div>{analysis_html}</div> |
|
|
<h2>Data Visualizations</h2> |
|
|
<div>{viz_html}</div> |
|
|
</div> |
|
|
""" |
|
|
|
|
|
return result_html, visualizations, cleaning_recommendations, analysis_insights |
|
|
|
|
|
|
|
|
with gr.Blocks(title="Data Visualization & Cleaning AI (Demo Mode)") as demo: |
|
|
gr.Markdown("# Data Visualization & Cleaning AI") |
|
|
gr.Markdown("**DEMO MODE** - Upload your data file (CSV, Excel, JSON, or TXT) and get automatic analysis and visualizations.") |
|
|
|
|
|
with gr.Row(): |
|
|
file_input = gr.File(label="Upload Data File") |
|
|
|
|
|
with gr.Tabs(): |
|
|
with gr.TabItem("Data Analysis"): |
|
|
with gr.Row(): |
|
|
analyze_button = gr.Button("Analyze Data") |
|
|
|
|
|
with gr.Tabs(): |
|
|
with gr.TabItem("Analysis & Visualizations"): |
|
|
output = gr.HTML(label="Results") |
|
|
with gr.TabItem("AI Cleaning Recommendations"): |
|
|
cleaning_recommendations_output = gr.Markdown(label="AI Recommendations") |
|
|
with gr.TabItem("AI Analysis Insights"): |
|
|
analysis_insights_output = gr.Markdown(label="Analysis Insights") |
|
|
with gr.TabItem("Raw Visualization Objects"): |
|
|
viz_output = gr.JSON(label="Visualization Objects") |
|
|
|
|
|
|
|
|
analyze_button.click( |
|
|
fn=demo_ui, |
|
|
inputs=[file_input], |
|
|
outputs=[output, viz_output, cleaning_recommendations_output, analysis_insights_output] |
|
|
) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |