SakibRumu
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,74 +1,89 @@
|
|
| 1 |
from fastai.vision.all import load_learner
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
#import pathlib
|
| 5 |
-
#temp=pathlib.PosixPath
|
| 6 |
-
#pathlib.PosixPath=pathlib.WindowsPath
|
| 7 |
-
# Custom Seafoam theme
|
| 8 |
from gradio.themes.base import Base
|
| 9 |
from gradio.themes.utils import colors, fonts, sizes
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
food_labels = [
|
| 15 |
-
'Baked Potato',
|
| 16 |
-
'
|
| 17 |
-
'
|
| 18 |
-
'
|
| 19 |
-
'
|
| 20 |
-
'
|
| 21 |
-
|
| 22 |
-
'Taquito',
|
| 23 |
-
'Apple Pie',
|
| 24 |
-
'Burger',
|
| 25 |
-
'Butter Naan',
|
| 26 |
-
'Chai',
|
| 27 |
-
'Chapati',
|
| 28 |
-
'Cheesecake',
|
| 29 |
-
'Chicken Curry',
|
| 30 |
-
'Chole Bhature',
|
| 31 |
-
'Dal Makhani',
|
| 32 |
-
'Dhokla',
|
| 33 |
-
'Fried Rice',
|
| 34 |
-
'Ice Cream',
|
| 35 |
-
'Idli',
|
| 36 |
-
'Jalebi',
|
| 37 |
-
'Kaathi Rolls',
|
| 38 |
-
'Kadai Paneer',
|
| 39 |
-
'Kulfi',
|
| 40 |
-
'Masala Dosa',
|
| 41 |
-
'Momos',
|
| 42 |
-
'Omelette',
|
| 43 |
-
'Paani Puri',
|
| 44 |
-
'Pakode',
|
| 45 |
-
'Pancakes',
|
| 46 |
-
'Quesadilla',
|
| 47 |
-
'Ratatouille',
|
| 48 |
-
'Samosa',
|
| 49 |
-
'Spring Rolls',
|
| 50 |
-
'Stuffed Bell Peppers',
|
| 51 |
-
'Tandoori Chicken',
|
| 52 |
-
'Uttapam',
|
| 53 |
-
'Veggie Burger',
|
| 54 |
-
'Waffles',
|
| 55 |
-
'Zucchini Bread']
|
| 56 |
|
| 57 |
-
model
|
|
|
|
| 58 |
|
|
|
|
| 59 |
def recognize_image(image):
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
print(pred)
|
| 63 |
-
return dict(zip(food_labels, map(float,probs)))
|
| 64 |
|
|
|
|
| 65 |
image = gr.Image()
|
| 66 |
label = gr.Label()
|
| 67 |
-
examples = [
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
iface.launch(inline=False,share=True)
|
|
|
|
| 1 |
from fastai.vision.all import load_learner
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from gradio.themes.base import Base
|
| 4 |
from gradio.themes.utils import colors, fonts, sizes
|
| 5 |
|
| 6 |
+
# Custom Seafoam theme
|
| 7 |
+
class Seafoam(Base):
|
| 8 |
+
def __init__(
|
| 9 |
+
self,
|
| 10 |
+
*,
|
| 11 |
+
primary_hue: colors.Color | str = colors.emerald,
|
| 12 |
+
secondary_hue: colors.Color | str = colors.blue,
|
| 13 |
+
neutral_hue: colors.Color | str = colors.blue,
|
| 14 |
+
spacing_size: sizes.Size | str = sizes.spacing_md,
|
| 15 |
+
radius_size: sizes.Size | str = sizes.radius_md,
|
| 16 |
+
text_size: sizes.Size | str = sizes.text_lg,
|
| 17 |
+
font: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 18 |
+
fonts.GoogleFont("Quicksand"),
|
| 19 |
+
"ui-sans-serif",
|
| 20 |
+
"sans-serif",
|
| 21 |
+
),
|
| 22 |
+
font_mono: fonts.Font | str | Iterable[fonts.Font | str] = (
|
| 23 |
+
fonts.GoogleFont("IBM Plex Mono"),
|
| 24 |
+
"ui-monospace",
|
| 25 |
+
"monospace",
|
| 26 |
+
),
|
| 27 |
+
):
|
| 28 |
+
super().__init__(
|
| 29 |
+
primary_hue=primary_hue,
|
| 30 |
+
secondary_hue=secondary_hue,
|
| 31 |
+
neutral_hue=neutral_hue,
|
| 32 |
+
spacing_size=spacing_size,
|
| 33 |
+
radius_size=radius_size,
|
| 34 |
+
text_size=text_size,
|
| 35 |
+
font=font,
|
| 36 |
+
font_mono=font_mono,
|
| 37 |
+
)
|
| 38 |
+
super().set(
|
| 39 |
+
body_background_fill="repeating-linear-gradient(45deg, *primary_200, *primary_200 10px, *primary_50 10px, *primary_50 20px)",
|
| 40 |
+
body_background_fill_dark="repeating-linear-gradient(45deg, *primary_800, *primary_800 10px, *primary_900 10px, *primary_900 20px)",
|
| 41 |
+
button_primary_background_fill="linear-gradient(90deg, *primary_300, *secondary_400)",
|
| 42 |
+
button_primary_background_fill_hover="linear-gradient(90deg, *primary_200, *secondary_300)",
|
| 43 |
+
button_primary_text_color="white",
|
| 44 |
+
button_primary_background_fill_dark="linear-gradient(90deg, *primary_600, *secondary_800)",
|
| 45 |
+
slider_color="*secondary_300",
|
| 46 |
+
slider_color_dark="*secondary_600",
|
| 47 |
+
block_title_text_weight="600",
|
| 48 |
+
block_border_width="3px",
|
| 49 |
+
block_shadow="*shadow_drop_lg",
|
| 50 |
+
button_shadow="*shadow_drop_lg",
|
| 51 |
+
button_large_padding="32px",
|
| 52 |
+
)
|
| 53 |
|
| 54 |
+
seafoam = Seafoam()
|
| 55 |
|
| 56 |
+
# Food labels
|
| 57 |
food_labels = [
|
| 58 |
+
'Baked Potato', 'Crispy Chicken', 'Donut', 'Fries', 'Hot Dog', 'Sandwich', 'Taco', 'Taquito',
|
| 59 |
+
'Apple Pie', 'Burger', 'Butter Naan', 'Chai', 'Chapati', 'Cheesecake', 'Chicken Curry',
|
| 60 |
+
'Chole Bhature', 'Dal Makhani', 'Dhokla', 'Fried Rice', 'Ice Cream', 'Idli', 'Jalebi',
|
| 61 |
+
'Kaathi Rolls', 'Kadai Paneer', 'Kulfi', 'Masala Dosa', 'Momos', 'Omelette', 'Paani Puri',
|
| 62 |
+
'Pakode', 'Pancakes', 'Quesadilla', 'Ratatouille', 'Samosa', 'Spring Rolls', 'Stuffed Bell Peppers',
|
| 63 |
+
'Tandoori Chicken', 'Uttapam', 'Veggie Burger', 'Waffles', 'Zucchini Bread'
|
| 64 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
# Load model
|
| 67 |
+
model = load_learner("food_model_v2.pkl")
|
| 68 |
|
| 69 |
+
# Prediction function
|
| 70 |
def recognize_image(image):
|
| 71 |
+
pred, idx, probs = model.predict(image)
|
| 72 |
+
return dict(zip(food_labels, map(float, probs)))
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
# Gradio interface
|
| 75 |
image = gr.Image()
|
| 76 |
label = gr.Label()
|
| 77 |
+
examples = ["food1.jpg", "food2.jpg", "food3.jpg", "food4.jpg"]
|
| 78 |
+
|
| 79 |
+
# Interface with Seafoam theme
|
| 80 |
+
iface = gr.Interface(
|
| 81 |
+
fn=recognize_image,
|
| 82 |
+
inputs=image,
|
| 83 |
+
outputs=label,
|
| 84 |
+
examples=examples,
|
| 85 |
+
theme=seafoam # Apply Seafoam theme here
|
| 86 |
+
)
|
| 87 |
|
| 88 |
+
# Launch the app
|
| 89 |
+
iface.launch(inline=False, share=True)
|