File size: 848 Bytes
712a6ef
 
 
 
 
 
 
 
 
9d5fbe1
712a6ef
 
9d5fbe1
712a6ef
 
 
9d5fbe1
712a6ef
 
 
 
 
 
 
 
9d5fbe1
712a6ef
 
 
 
 
 
 
 
 
 
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
# import gradio as gr
#
# def greet(name):
#     return "Hello " + name + "!!"
#
# demo = gr.Interface(fn=greet, inputs="text", outputs="text")
# demo.launch()
#

import gradio as gr
from sklearn.neighbors import KNeighborsClassifier
import numpy as np

# Training data
X = np.array([[1, 2], [2, 3], [3, 1], [6, 5], [7, 7], [8, 6]])
y = np.array([0, 0, 0, 1, 1, 1])

# Training the model
model = KNeighborsClassifier(n_neighbors=3)
model.fit(X, y)

# Define the prediction function
def classify_point(x, y):
    prediction = model.predict([[x, y]])
    return "Class " + str(prediction[0])

# Create a Gradio interface
demo = gr.Interface(
    fn=classify_point,
    inputs=["number", "number"],
    outputs="text",
    description="Predict the class of a point based on its coordinates using K-Nearest Neighbors"
)

# Launch the app
demo.launch()