Spaces:
Sleeping
Sleeping
Hikmat Farhat
commited on
Commit
·
ff5c137
1
Parent(s):
9f8a9a6
initial commit
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit_image_select import image_select
|
3 |
+
from PIL import Image
|
4 |
+
import pandas as pd
|
5 |
+
from transformers import AutoModel
|
6 |
+
import torch
|
7 |
+
from torchvision.datasets import MNIST
|
8 |
+
from torchvision.transforms import ToTensor
|
9 |
+
import numpy as np
|
10 |
+
st.title("Streamlit GUI")
|
11 |
+
|
12 |
+
classifier=AutoModel.from_pretrained("hikmatfarhat/MNIST_Classifier",trust_remote_code=True)
|
13 |
+
softmax=torch.nn.Softmax(dim=1)
|
14 |
+
np.set_printoptions(precision=3,suppress=True)
|
15 |
+
imgs=[]
|
16 |
+
|
17 |
+
for i in range(15):
|
18 |
+
imgs.append(Image.open(f"img{i}.png"))
|
19 |
+
image=image_select("select a digit",imgs,use_container_width=False)
|
20 |
+
image=ToTensor()(image)
|
21 |
+
output=classifier(image)
|
22 |
+
output=torch.squeeze(softmax(output))
|
23 |
+
output=output.detach().numpy()
|
24 |
+
## streamlit doesn't show the proper label for the column name when using numpy array
|
25 |
+
## so we convert it to pandas dataframe
|
26 |
+
df=pd.DataFrame(output,columns=["prob"])
|
27 |
+
st.dataframe(df,column_config={"prob":st.column_config.Column(
|
28 |
+
"Probability",required=True)}
|
29 |
+
,hide_index=False
|
30 |
+
)
|
img0.png
ADDED
![]() |
img1.png
ADDED
![]() |
img10.png
ADDED
![]() |
img11.png
ADDED
![]() |
img12.png
ADDED
![]() |
img13.png
ADDED
![]() |
img14.png
ADDED
![]() |
img2.png
ADDED
![]() |
img3.png
ADDED
![]() |
img4.png
ADDED
![]() |
img5.png
ADDED
![]() |
img6.png
ADDED
![]() |
img7.png
ADDED
![]() |
img8.png
ADDED
![]() |
img9.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
torchvision
|
3 |
+
PIL
|
4 |
+
streamlit_image_select
|
5 |
+
numpy
|