Vishalpainjane commited on
Commit
ab360d8
·
verified ·
1 Parent(s): d4ae202

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import numpy as np
3
+ import seaborn as sns
4
+ import matplotlib.pyplot as plt
5
+ import gradio as gr
6
+ import warnings
7
+ warnings.filterwarnings("ignore")
8
+
9
+ url='https://drive.google.com/file/d/1VfCaU5vFVWsSYrvKQF2x9iS6I7KoWEVH/view?usp=share_link'
10
+ url='https://drive.google.com/uc?id=' + url.split('/')[-2]
11
+ df = pd.read_csv(url)
12
+
13
+ df['cf_rating']=df['cf_rating'].astype(str)
14
+ df['cc_rating']=df['cc_rating'].astype(str)
15
+ df['cf_username']=df['cf_username'].astype(str)
16
+ df['cc_username']=df['cc_username'].astype(str)
17
+ df['ss_username']=df['ss_username'].astype(str)
18
+
19
+ only_cc = df[(df['cf_username'] == "nan")]
20
+ only_cf = df[(df['cc_username'] == "nan")]
21
+ both_cc_cf = df[(df['cf_username'] != "nan") & (df['cf_rating'] != "nan") & (df['cc_username'] != "nan") & (df['cc_rating'] != "nan")]
22
+ both_cc_cf.drop(columns=['ss_username','cf_username','cc_username'],inplace=True)
23
+
24
+
25
+ def linear_regression(X, y):
26
+ #calculating mean
27
+ mean_x = np.mean(X)
28
+ mean_y = np.mean(y)
29
+
30
+ n = 0
31
+ d = 0
32
+ for i in range(len(X)):
33
+ n += (X[i] - mean_x) * (y[i] - mean_y)
34
+ d += (X[i] - mean_x) ** 2
35
+ #calculating weights and bias
36
+ w = n/d
37
+ b = mean_y-(w * mean_x)
38
+
39
+ return (b[0], w[0])
40
+
41
+ X=both_cc_cf['cc_rating'].values.reshape(-1,1).astype(float)
42
+ Y=both_cc_cf['cf_rating'].values.reshape(-1,1).astype(float)
43
+
44
+ b_cc, w_cc = linear_regression(X,Y)
45
+ b_cf, w_cf = linear_regression(Y,X)
46
+
47
+ def predict_rating(platform, current_rating):
48
+ if platform == "CodeChef":
49
+ predicted_rating = current_rating * w_cc + b_cc
50
+ else:
51
+ predicted_rating = current_rating * w_cf + b_cf
52
+ return int(predicted_rating)
53
+
54
+ interface = gr.Interface(
55
+ fn=predict_rating,
56
+ inputs=[
57
+ gr.Radio(choices=["CodeChef", "Codeforces"], label="Platform"),
58
+ gr.Number(label="Current Rating")
59
+ ],
60
+ outputs="number",
61
+ title="CodeChef and Codeforces Rating Predictor",
62
+ )
63
+
64
+ interface.launch()