Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445import pandas as pdfrom sklearn.model_selection import train_test_splitfrom sklearn.linear_model import LinearRegressionimport joblibimport gradio as gr
# Load the data from the CSV filedata = pd.read_csv('data.csv')
# Encode 'Price' column into numerical valuesdata['Price'] = data['Price'].apply(lambda x: 0 if x == 'Free' else 1)
# Convert 'Size' and 'Reviews' columns to numerical valuesdata['Size'] = data['Size'].str.replace('MB', '').astype(float)data['Reviews'] = data['Reviews'].str.replace('M', '').astype(float)
# Select the features (reviews, size, and price) and the target variable (rating)X = data[['Reviews', 'Size', 'Price']]y = data['Rating']
# Split the data into training and testing setsX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Create a linear regression modelmodel = LinearRegression()
# Train the modelmodel.fit(X_train, y_train)
# Save the trained modeljoblib.dump(model, 'linear_regression_model.pkl')
# Define a function to make predictions using the modeldef predict_rating(reviews, size, price): # Load the trained model loaded_model = joblib.load('linear_regression_model.pkl') # Make predictions using the loaded model predicted_rating = loaded_model.predict([[reviews, size, price]]) return predicted_rating[0]
# Create a Gradio interface for the modeliface = gr.Interface(fn=predict_rating, inputs=["number", "number", "number"], outputs="number", title="App Rating Predictor", examples=[[20, 25.1, 0], [45, 26.7, 1], [60, 30.2, 0]], description="Enter the number of reviews, size(without 'MB' word), and price(0 = paid, 1 = free) of your app to predict its rating.")
# Launch the Gradio interface with a user guideiface.launch(share=False, debug=True, enable_queue=True)app.pyAdded+45