jatnikonm commited on
Commit
712a6ef
1 Parent(s): 0842248

add simple ml code

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -1,8 +1,36 @@
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
8
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import gradio as gr
2
+ #
3
+ # def greet(name):
4
+ # return "Hello " + name + "!!"
5
+ #
6
+ # demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
+ # demo.launch()
8
+ #
9
+
10
  import gradio as gr
11
+ from sklearn.neighbors import KNeighborsClassifier
12
+ import numpy as np
13
 
14
+ # Training data
15
+ X = np.array([[1, 2], [2, 3], [3, 1], [6, 5], [7, 7], [8, 6]])
16
+ y = np.array([0, 0, 0, 1, 1, 1])
17
 
18
+ # Training the model
19
+ model = KNeighborsClassifier(n_neighbors=3)
20
+ model.fit(X, y)
21
+
22
+ # Define the prediction function
23
+ def classify_point(x, y):
24
+ prediction = model.predict([[x, y]])
25
+ return "Class " + str(prediction[0])
26
 
27
+ # Create a Gradio interface
28
+ demo = gr.Interface(
29
+ fn=classify_point,
30
+ inputs=["number", "number"],
31
+ outputs="text",
32
+ description="Predict the class of a point based on its coordinates using K-Nearest Neighbors"
33
+ )
34
+
35
+ # Launch the app
36
+ demo.launch()