Nurisslam commited on
Commit
455123e
·
verified ·
1 Parent(s): 446424f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -34
app.py CHANGED
@@ -1,41 +1,27 @@
1
- import gradio as gr
 
2
  from transformers import pipeline
3
 
4
- # Демонстрация үшін жалпы image-classification pipeline қолданамыз
5
- # Нақты жағдайда өзің fine-tune жасаған модельді осында жүктейсің
6
- classifier = pipeline("image-classification", model="google/vit-base-patch16-224")
7
 
8
- # Класстарды мысал ретінде береміз (қолданушы өз датасына бейімдейді)
9
- # Мысалы: "Дене сау", "Алдыңғы бампер бұзылған", "Шина зақымдалған", т.б.
10
- CUSTOM_LABELS = {
11
- "n02124075": "✅ Машина қалыпты",
12
- "n02958343": "⚠️ Бампер бұзылған",
13
- "n02974003": "⚠️ Шина зақымдалған",
14
- "n03770679": "⚠️ Қақпақ (капот) зақымдалған"
15
- }
16
 
17
- def predict(image):
18
- preds = classifier(image)
19
- if not preds:
20
- return "❌ Ақау анықталмады"
21
-
22
- # Ең сенімді нәтижені аламыз
23
- top_pred = preds[0]
24
- label = top_pred["label"]
25
- score = top_pred["score"]
26
 
27
- # Егер кастом лейбл бар болса
28
- readable = CUSTOM_LABELS.get(label, label)
29
- return f"{readable} (сенімділік: {score:.2f})"
30
 
31
- # Gradio интерфейс
32
- demo = gr.Interface(
33
- fn=predict,
34
- inputs=gr.Image(type="pil", label="Машина суретін жүктеңіз"),
35
- outputs=gr.Textbox(label="Диагноз"),
36
- title="🚗 Машина ақауын суреттен анықтау",
37
- description="Фото жүктеңіз, ИИ қай жерінің бұзылғанын айтады."
38
- )
39
 
40
- if __name__ == "__main__":
41
- demo.launch()
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
  from transformers import pipeline
4
 
5
+ # YOLOv11 segmentation модель
6
+ pipe = pipeline("image-segmentation", model="harpreetsahota/car-dd-segmentation-yolov11")
 
7
 
8
+ st.set_page_config(page_title="Car Damage Detection", page_icon="🚗", layout="centered")
9
+ st.title("🚗 Машина зақымын анықтау (YOLOv11 Segmentation)")
 
 
 
 
 
 
10
 
11
+ uploaded_file = st.file_uploader("Машина суретін жүктеңіз", type=["jpg", "jpeg", "png"])
 
 
 
 
 
 
 
 
12
 
13
+ if uploaded_file is not None:
14
+ image = Image.open(uploaded_file).convert("RGB")
15
+ st.image(image, caption="Жүктелген сурет", use_column_width=True)
16
 
17
+ st.write("🔎 Анализ жасалуда...")
18
+ results = pipe(image)
 
 
 
 
 
 
19
 
20
+ st.subheader("📋 Нәтиже:")
21
+ if results:
22
+ for obj in results:
23
+ label = obj.get("label", "Белгісіз")
24
+ score = obj.get("score", 0)
25
+ st.success(f"{label} (сенімділік: {score:.2f})")
26
+ else:
27
+ st.info("Зақым табылмады ✅")