Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +65 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
# Create the inputs list with dropdown menus and sliders
|
| 7 |
+
inputs = [
|
| 8 |
+
gr.Dropdown(
|
| 9 |
+
choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan',
|
| 10 |
+
'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'],
|
| 11 |
+
label="Batting Team"
|
| 12 |
+
),
|
| 13 |
+
gr.Dropdown(
|
| 14 |
+
choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan',
|
| 15 |
+
'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'],
|
| 16 |
+
label="Bowling Team"
|
| 17 |
+
),
|
| 18 |
+
gr.Slider(minimum=0, maximum=500, step=1, label="Total Runs"),
|
| 19 |
+
gr.Slider(minimum=0, maximum=11, step=1, label="Total Wickets"),
|
| 20 |
+
gr.Slider(minimum=0.0, maximum=49.6, step=0.1, label="Overs"),
|
| 21 |
+
gr.Slider(minimum=0, maximum=500, step=1, label="Runs last 5 overs"),
|
| 22 |
+
gr.Slider(minimum=0, maximum=11,step=1, label="Wickets last 5 overs"),
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# Create a function to make predictions
|
| 27 |
+
def predict_accident(
|
| 28 |
+
batting_team,
|
| 29 |
+
bowling_team,
|
| 30 |
+
total_runs,
|
| 31 |
+
total_wickets,
|
| 32 |
+
overs,
|
| 33 |
+
runs_last_5_overs,
|
| 34 |
+
wickets_last_5_overs
|
| 35 |
+
):
|
| 36 |
+
# Replace the URL with the actual endpoint you want to send the request to
|
| 37 |
+
url = "https://parthcodes-test-prediction-model.hf.space/prediction"
|
| 38 |
+
|
| 39 |
+
# Replace the payload with the data you want to send in the request body
|
| 40 |
+
payload = {"batting_team": batting_team, "bowling_team": bowling_team, "total_runs": total_runs, "total_wickets": total_wickets, "overs": overs, "runs_last_5_overs": runs_last_5_overs, "wickets_last_5_overs": wickets_last_5_overs}
|
| 41 |
+
|
| 42 |
+
# Convert the payload to JSON
|
| 43 |
+
json_payload = json.dumps(payload)
|
| 44 |
+
|
| 45 |
+
# Set the headers to indicate that you are sending JSON
|
| 46 |
+
headers = {'Content-Type': 'application/json'}
|
| 47 |
+
|
| 48 |
+
# Send the POST request
|
| 49 |
+
response = requests.post(url, data=json_payload, headers=headers)
|
| 50 |
+
|
| 51 |
+
label = f"Score Prediction: {response.json().get('prediction')}"
|
| 52 |
+
return label
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# Create the Gradio interface
|
| 56 |
+
title = "ICC World Cup Score Prediction"
|
| 57 |
+
description = "Predict the score of a ICC World Cup matches."
|
| 58 |
+
output_label = [gr.Label(num_top_classes=4)]
|
| 59 |
+
gr.Interface(
|
| 60 |
+
fn=predict_accident,
|
| 61 |
+
inputs=inputs,
|
| 62 |
+
outputs=output_label,
|
| 63 |
+
title=title,
|
| 64 |
+
description=description,
|
| 65 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
numpy
|
| 3 |
+
joblib
|