Spaces:
Build error
Build error
[add] initial code
Browse filesfirst commit example
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
# reading the trained model from file
|
| 5 |
+
with open('fruit_classifier.pkl', 'rb') as file:
|
| 6 |
+
trained_model = pickle.load(file)
|
| 7 |
+
|
| 8 |
+
# list of all available colors
|
| 9 |
+
list_colors = ['Green','Yellow','Red'] # 0=Green, 1=Yellow, 2=Red
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def classify_fruits(weight, color, diameter):
|
| 13 |
+
|
| 14 |
+
# convert color 'text' to number
|
| 15 |
+
color_number = list_colors.index(color)
|
| 16 |
+
|
| 17 |
+
results = trained_model.predict([[weight, color_number, diameter]])
|
| 18 |
+
return results[0]
|
| 19 |
+
|
| 20 |
+
# color options
|
| 21 |
+
color_radio = gr.Radio(choices=list_colors, label="choose a color")
|
| 22 |
+
|
| 23 |
+
# creating basic interface
|
| 24 |
+
app = gr.Interface(fn=classify_fruits, inputs=['number',color_radio,'number'], outputs=['text'])
|
| 25 |
+
|
| 26 |
+
# running the app
|
| 27 |
+
app.launch()
|