adarshjha01
commited on
Commit
•
c12a143
1
Parent(s):
a846a10
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from sklearn.linear_model import LinearRegression
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Load dataset
|
6 |
+
teams = pd.read_csv("teams.csv")
|
7 |
+
teams = teams[['team', 'country', 'year', 'athletes', 'age', 'prev_medals', 'medals']]
|
8 |
+
teams = teams.dropna()
|
9 |
+
|
10 |
+
# Split data into training and testing sets
|
11 |
+
train = teams[teams['year'] < 2012].copy()
|
12 |
+
test = teams[teams['year'] >= 2012].copy()
|
13 |
+
|
14 |
+
# Define predictors and target
|
15 |
+
predictors = ['athletes', 'prev_medals']
|
16 |
+
target = 'medals'
|
17 |
+
|
18 |
+
# Train the Linear Regression model
|
19 |
+
reg = LinearRegression()
|
20 |
+
reg.fit(train[predictors], train['medals'])
|
21 |
+
|
22 |
+
# Define the prediction function
|
23 |
+
def predict_medals(athletes: int, prev_medals: int):
|
24 |
+
input_data = pd.DataFrame({'athletes': [athletes], 'prev_medals': [prev_medals]})
|
25 |
+
prediction = reg.predict(input_data)[0]
|
26 |
+
return max(0, round(prediction))
|
27 |
+
|
28 |
+
# Create Gradio interface
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=predict_medals,
|
31 |
+
inputs=[
|
32 |
+
gr.Number(label="Number of Athletes"),
|
33 |
+
gr.Number(label="Previous Medals Won"),
|
34 |
+
],
|
35 |
+
outputs="number",
|
36 |
+
title="Olympics Medal Prediction",
|
37 |
+
description="Predict the number of medals a team might win based on athletes and previous medals."
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the interface
|
41 |
+
if __name__ == "__main__":
|
42 |
+
interface.launch()
|