Spaces:
Sleeping
Sleeping
Update app.py (#5)
Browse files- Update app.py (3947125c06391172f15872e1aa0350c1873eb577)
Co-authored-by: Durdu <[email protected]>
app.py
CHANGED
@@ -1,4 +1,25 @@
|
|
|
|
1 |
from ultralytics import YOLO
|
|
|
2 |
|
|
|
3 |
model = YOLO('yolov8m-seg.pt')
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
from ultralytics import YOLO
|
3 |
+
import cv2
|
4 |
|
5 |
+
# Laden Sie das YOLO-Modell
|
6 |
model = YOLO('yolov8m-seg.pt')
|
7 |
+
|
8 |
+
# Funktion für die Vorhersage und Rückgabe des bearbeiteten Bildes
|
9 |
+
def predict_and_visualize(image):
|
10 |
+
# Führen Sie die Vorhersage durch
|
11 |
+
prediction = model.predict(image, imgsz=(1024, 1024), show=False, save=True)
|
12 |
+
# Nehmen Sie das generierte Bild, das von YOLO gespeichert wurde
|
13 |
+
|
14 |
+
processed_image_path = prediction.__getitem__(0).save_dir + "/" +prediction.__getitem__(0).path
|
15 |
+
print(processed_image_path)
|
16 |
+
#print("Image PATH: ",processed_image_path)
|
17 |
+
|
18 |
+
# Laden Sie das Bild und geben Sie es zurück
|
19 |
+
processed_image = cv2.imread(processed_image_path)
|
20 |
+
return processed_image
|
21 |
+
|
22 |
+
# Gradio-Schnittstelle für die Bildbearbeitungsfunktion
|
23 |
+
iface = gr.Interface(fn=predict_and_visualize, inputs="image", outputs="image")
|
24 |
+
iface.launch()
|
25 |
+
|