Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| from sklearn.linear_model import LinearRegression | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.preprocessing import OneHotEncoder | |
| def trend_analysis(df, target_column): | |
| # Handle categorical variables | |
| categorical_columns = ['country', 'public/pro', 'language'] | |
| df = pd.get_dummies(df, columns=categorical_columns) | |
| # Split the data into training and testing sets | |
| X_train, X_test, y_train, y_test = train_test_split(df.drop(target_column, axis=1), df[target_column], test_size=0.2, random_state=42) | |
| # Train the model | |
| model = LinearRegression() | |
| model.fit(X_train, y_train) | |
| # Use the model to make predictions | |
| df['prediction'] = model.predict(df.drop(target_column, axis=1)) | |
| return df | |
| def process_csv(file_path): | |
| try: | |
| # Read CSV file | |
| df = pd.read_csv(file_path, error_bad_lines=False) | |
| # Perform trend analysis | |
| target_column = 'unit price' # Replace with the name of your target column | |
| df = trend_analysis(df, target_column) | |
| # Save the processed DataFrame to a new CSV file (optional) | |
| df.to_csv("processed_data.csv", index=False) | |
| return "Processing completed. Check 'processed_data.csv' for results." | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| iface = gr.Interface( | |
| fn=process_csv, | |
| inputs=gr.File(), | |
| outputs=gr.Textbox(), | |
| live=True, | |
| ) | |
| if __name__ == '__main__': | |
| iface.launch() |