gfs1000 commited on
Commit
21914e7
1 Parent(s): 0c666b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from sklearn.linear_model import LinearRegression
4
+ from sklearn.model_selection import train_test_split
5
+ from sklearn.preprocessing import OneHotEncoder
6
+
7
+ def trend_analysis(df, target_column):
8
+ # Handle categorical variables
9
+ categorical_columns = ['country', 'public/pro', 'language']
10
+ df = pd.get_dummies(df, columns=categorical_columns)
11
+
12
+ # Split the data into training and testing sets
13
+ 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)
14
+
15
+ # Train the model
16
+ model = LinearRegression()
17
+ model.fit(X_train, y_train)
18
+
19
+ # Use the model to make predictions
20
+ df['prediction'] = model.predict(df.drop(target_column, axis=1))
21
+
22
+ return df
23
+
24
+ def process_csv(file_path):
25
+ try:
26
+ # Read CSV file
27
+ df = pd.read_csv(file_path, error_bad_lines=False)
28
+
29
+ # Perform trend analysis
30
+ target_column = 'unit price' # Replace with the name of your target column
31
+ df = trend_analysis(df, target_column)
32
+
33
+ # Save the processed DataFrame to a new CSV file (optional)
34
+ df.to_csv("processed_data.csv", index=False)
35
+
36
+ return "Processing completed. Check 'processed_data.csv' for results."
37
+ except Exception as e:
38
+ return f"Error: {str(e)}"
39
+
40
+ iface = gr.Interface(
41
+ fn=process_csv,
42
+ inputs=gr.File(),
43
+ outputs=gr.Textbox(),
44
+ live=True,
45
+ )
46
+
47
+ if __name__ == '__main__':
48
+ iface.launch()