File size: 2,316 Bytes
e5ce7ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1867856
e5ce7ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import gradio as gr
import json

import requests

# Create the inputs list with dropdown menus and sliders
inputs = [
    gr.Dropdown(
        choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan',
                 'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'],
        label="Batting Team"
    ),
    gr.Dropdown(
        choices=['Afghanistan', 'Australia', 'Bangladesh', 'England', 'India', 'Ireland', 'New Zealand', 'Pakistan',
                 'South Africa', 'Sri Lanka', 'West Indies', 'Zimbabwe'],
        label="Bowling Team"
    ),
    gr.Slider(minimum=0, maximum=500, step=1, label="Total Runs"),
    gr.Slider(minimum=0, maximum=11, step=1, label="Total Wickets"),
    gr.Slider(minimum=0.0, maximum=49.6, step=0.1, label="Overs"),
    gr.Slider(minimum=0, maximum=500, step=1, label="Runs last 5 overs"),
    gr.Slider(minimum=0, maximum=11,step=1, label="Wickets last 5 overs"),
]


# Create a function to make predictions
def predict_accident(
    batting_team,
    bowling_team,
    total_runs,
    total_wickets,
    overs,
    runs_last_5_overs,
    wickets_last_5_overs
):
    # Replace the URL with the actual endpoint you want to send the request to
    url = "https://abhicodes-icc-prediction-model-api.hf.space/prediction"

    # Replace the payload with the data you want to send in the request body
    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}

    # Convert the payload to JSON
    json_payload = json.dumps(payload)

    # Set the headers to indicate that you are sending JSON
    headers = {'Content-Type': 'application/json'}

    # Send the POST request
    response = requests.post(url, data=json_payload, headers=headers)

    label = f"Score Prediction: {response.json().get('prediction')}"
    return label


# Create the Gradio interface
title = "ICC World Cup Score Prediction"
description = "Predict the score of a ICC World Cup matches."
output_label = [gr.Label(num_top_classes=4)]
gr.Interface(
    fn=predict_accident,
    inputs=inputs,
    outputs=output_label,
    title=title,
    description=description,
).launch()