shadownada commited on
Commit
3feed6e
·
verified ·
1 Parent(s): 9ab936d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -2
app.py CHANGED
@@ -1,4 +1,117 @@
1
  import streamlit as st
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
+ from PIL import Image
4
 
5
+ MODEL_1 = "google/vit-base-patch16-224"
6
+ MIN_ACEPTABLE_SCORE = 0.1
7
+ MAX_N_LABELS = 5
8
+ MODEL_2 = "nateraw/vit-age-classifier"
9
+ MODELS = [
10
+ "google/efficientnet-b0",
11
+ "google/vit-base-patch16-224", #Classifição geral
12
+ "nateraw/vit-age-classifier", #Classifição de idade
13
+ "microsoft/resnet-50", #Classifição geral
14
+ "Falconsai/nsfw_image_detection", #Classifição NSFW
15
+ "cafeai/cafe_aesthetic", #Classifição de estética
16
+ "microsoft/resnet-18", #Classifição geral
17
+ "microsoft/resnet-34", #Classifição geral escolhida pelo copilot
18
+ "microsoft/resnet-101", #Classifição geral escolhida pelo copilot
19
+ "microsoft/resnet-152", #Classifição geral escolhida pelo copilot
20
+ "microsoft/swin-tiny-patch4-window7-224",#Classifição geral
21
+ "-- Reinstated on testing--",
22
+ "microsoft/beit-base-patch16-224-pt22k-ft22k", #Classifição geral
23
+ "-- New --",
24
+ "-- Still in the testing process --",
25
+ "facebook/convnext-large-224", #Classifição geral
26
+ "timm/resnet50.a1_in1k", #Classifição geral
27
+ "timm/mobilenetv3_large_100.ra_in1k", #Classifição geral
28
+ "trpakov/vit-face-expression", #Classifição de expressão facial
29
+ "rizvandwiki/gender-classification", #Classifição de gênero
30
+ "#q-future/one-align", #Classifição geral
31
+ "LukeJacob2023/nsfw-image-detector", #Classifição NSFW
32
+ "vit-base-patch16-224-in21k", #Classifição geral
33
+ "not-lain/deepfake", #Classifição deepfake
34
+ "carbon225/vit-base-patch16-224-hentai", #Classifição hentai
35
+ "facebook/convnext-base-224-22k-1k", #Classifição geral
36
+ "facebook/convnext-large-224", #Classifição geral
37
+ "facebook/convnext-tiny-224",#Classifição geral
38
+ "nvidia/mit-b0", #Classifição geral
39
+ "microsoft/resnet-18", #Classifição geral
40
+ "microsoft/swinv2-base-patch4-window16-256", #Classifição geral
41
+ "andupets/real-estate-image-classification", #Classifição de imóveis
42
+ "timm/tf_efficientnetv2_s.in21k", #Classifição geral
43
+ "timm/convnext_tiny.fb_in22k",
44
+ "DunnBC22/vit-base-patch16-224-in21k_Human_Activity_Recognition", #Classifição de atividade humana
45
+ "FatihC/swin-tiny-patch4-window7-224-finetuned-eurosat-watermark", #Classifição geral
46
+ "aalonso-developer/vit-base-patch16-224-in21k-clothing-classifier", #Classifição de roupas
47
+ "RickyIG/emotion_face_image_classification", #Classifição de emoções
48
+ "shadowlilac/aesthetic-shadow" #Classifição de estética
49
+ ]
50
+
51
+ def classify(image, model):
52
+ classifier = pipeline("image-classification", model=model)
53
+ result= classifier(image)
54
+ return result
55
+
56
+ def save_result(result):
57
+ st.write("In the future, this function will save the result in a database.")
58
+
59
+ def print_result(result):
60
+
61
+ comulative_discarded_score = 0
62
+ for i in range(len(result)):
63
+ if result[i]['score'] < MIN_ACEPTABLE_SCORE:
64
+ comulative_discarded_score += result[i]['score']
65
+ else:
66
+ st.write(result[i]['label'])
67
+ st.progress(result[i]['score'])
68
+ st.write(result[i]['score'])
69
+
70
+ st.write(f"comulative_discarded_score:")
71
+ st.progress(comulative_discarded_score)
72
+ st.write(comulative_discarded_score)
73
+
74
+
75
+
76
+ def main():
77
+ st.title("Image Classification")
78
+ st.write("This is a simple web app to test and compare different image classifier models using Hugging Face's image-classification pipeline.")
79
+ st.write("From time to time more models will be added to the list. If you want to add a model, please open an issue on the GitHub repository.")
80
+ st.write("If you like this project, please consider liking it or buying me a coffee. It will help me to keep working on this and other projects. Thank you!")
81
+
82
+ # Buy me a Coffee Setup
83
+ bmc_link = "https://www.buymeacoffee.com/nuno.tome"
84
+ # image_url = "https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png?w=150" # Image URL
85
+ image_url = "https://i.giphy.com/RETzc1mj7HpZPuNf3e.webp" # Image URL
86
+
87
+ image_size = "150px" # Image size
88
+ #image_link_markdown = f"<img src='{image_url}' width='25%'>"
89
+ image_link_markdown = f"[![Buy Me a Coffee]({image_url})]({bmc_link})"
90
+
91
+ #image_link_markdown = f"[![Buy Me a Coffee]({image_url})]({bmc_link})" # Create a clickable image link
92
+
93
+ st.markdown(image_link_markdown, unsafe_allow_html=True) # Display the image link
94
+ # Buy me a Coffee Setup
95
+
96
+ #st.markdown("<img src='https://helloimjessa.files.wordpress.com/2021/06/bmc-button.png?w=1024' width='15%'>", unsafe_allow_html=True)
97
+
98
+ input_image = st.file_uploader("Upload Image")
99
+ shosen_model = st.selectbox("Select the model to use", MODELS)
100
+
101
+
102
+ if input_image is not None:
103
+ image_to_classify = Image.open(input_image)
104
+ st.image(image_to_classify, caption="Uploaded Image")
105
+ if st.button("Classify"):
106
+ image_to_classify = Image.open(input_image)
107
+ classification_obj1 =[]
108
+ #avable_models = st.selectbox
109
+
110
+ classification_result = classify(image_to_classify, shosen_model)
111
+ classification_obj1.append(classification_result)
112
+ print_result(classification_result)
113
+ save_result(classification_result)
114
+
115
+
116
+ if __name__ == "__main__":
117
+ main()