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