Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,56 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastai import *
|
2 |
+
from fastcore.all import *
|
3 |
+
from fastai.vision.all import *
|
4 |
+
import pandas as pd
|
5 |
+
import re
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
|
9 |
+
def get_x(data_set):
|
10 |
+
return Path(data_set['image_path'])
|
11 |
+
|
12 |
+
def get_y(data_set):
|
13 |
+
return data_set['bf_est']
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
def new_splitter(df):
|
18 |
+
# Get the unique values in the 'id' column
|
19 |
+
unique_ids = df['id'].unique()
|
20 |
+
|
21 |
+
# Shuffle the unique values
|
22 |
+
np.random.seed(42)
|
23 |
+
np.random.shuffle(unique_ids)
|
24 |
+
|
25 |
+
# Calculate the number of unique values to be included in the first dataframe
|
26 |
+
num_unique_in_test = int(np.ceil(len(unique_ids) * 0.8))
|
27 |
+
|
28 |
+
# Get the first 'num_unique_in_df1' unique values
|
29 |
+
test_ids = unique_ids[:num_unique_in_test]
|
30 |
+
|
31 |
+
# Get the rows of the original dataframe that contain the 'df1_ids'
|
32 |
+
test = df.index[df['id'].isin(test_ids)].tolist()
|
33 |
+
|
34 |
+
# Get the rest of the rows from the original dataframe
|
35 |
+
valid = df.index[~df['id'].isin(test_ids)].tolist()
|
36 |
+
|
37 |
+
return test, valid
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
learner = load_learner("bf_model.pkl")
|
42 |
+
|
43 |
+
def predict_bf(img):
|
44 |
+
# pil_img = PILImage.create(img)
|
45 |
+
return round(float(learner.predict(img)[1]),2)
|
46 |
+
|
47 |
+
image = gr.Image(shape=(192,192))
|
48 |
+
# label = gr.float()
|
49 |
+
intf = gr.Interface(fn =predict_bf, inputs = image, outputs = "number" )
|
50 |
+
intf.launch(inline= False, share=True)
|
51 |
+
|
52 |
+
# def greet(name):
|
53 |
+
# return "Hello " + name + "!!" + "This is version 2!!!"
|
54 |
+
|
55 |
+
# iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
56 |
+
# iface.launch()
|