Nurisslam commited on
Commit
bd9a5b3
·
verified ·
1 Parent(s): 578a611

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -25
app.py CHANGED
@@ -1,33 +1,23 @@
1
  import streamlit as st
2
- from roboflow import Roboflow
3
  from PIL import Image
4
- import tempfile
5
 
6
- # Roboflow дайын модель
7
- rf = Roboflow(api_key="K1QpyyTZoYzAatHOhuZS")
8
- workspace = rf.workspace("Nurisslam") # workspace атауы
9
- project = workspace.project("car-damage-detection5") # project атауы
10
- model = project.version(1).model
11
 
12
- st.title("🚗 Машина зақымын анықтау (Roboflow моделімен)")
13
 
14
  uploaded_file = st.file_uploader("Суретті жүктеңіз", type=["jpg","jpeg","png"])
15
  if uploaded_file is not None:
16
- image = Image.open(uploaded_file)
17
  st.image(image, caption="Жүктелген сурет", use_column_width=True)
18
- st.write("🔎 Анализ жасалуда...")
19
-
20
- # уақытша файл жасау
21
- with tempfile.NamedTemporaryFile(suffix=".jpg") as tmp:
22
- image.save(tmp.name)
23
- result = model.predict(tmp.name, confidence=40).json()
24
-
25
- if "predictions" in result:
26
- lines = []
27
- for p in result["predictions"]:
28
- cls = p["class"]
29
- conf = p["confidence"]
30
- lines.append(f"{cls} (сенімділік: {conf:.2f})")
31
- st.success("\n".join(lines))
32
- else:
33
- st.warning("Ақау табылмады")
 
1
  import streamlit as st
 
2
  from PIL import Image
3
+ from transformers import pipeline
4
 
5
+ # Модель
6
+ pipe = pipeline("image-classification", model="beingamit99/car_damage_detection")
 
 
 
7
 
8
+ st.title("🚗 Машинаның зақымын анықтау (Hugging Face модельмен)")
9
 
10
  uploaded_file = st.file_uploader("Суретті жүктеңіз", type=["jpg","jpeg","png"])
11
  if uploaded_file is not None:
12
+ image = Image.open(uploaded_file).convert("RGB")
13
  st.image(image, caption="Жүктелген сурет", use_column_width=True)
14
+
15
+ with st.spinner("Анализ жасалуда..."):
16
+ preds = pipe(image)
17
+
18
+ st.subheader("📋 Нәтиже:")
19
+ # Жоғары сенімді нәтиже көрсетеміз
20
+ best = preds[0]
21
+ label = best["label"]
22
+ score = best["score"]
23
+ st.success(f"{label} (сенімділік: {score:.2f})")