Dannel commited on
Commit
ffa9be3
·
verified ·
1 Parent(s): a1461d7

Update app.py

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