Spaces:
Runtime error
Runtime error
Create app.py
Browse files123456789101112131415161718192021222324252627282930313233import gradio as grfrom PIL import Imageimport requestsfrom transformers import DetrForObjectDetection, DetrFeatureExtractorimport torch
# 모델과 피처 추출기 로드model_id = "facebook/detr-resnet-50"model = DetrForObjectDetection.from_pretrained(model_id)feature_extractor = DetrFeatureExtractor.from_pretrained(model_id)
def object_detection(image): # 이미지에서 피처 추출 inputs = feature_extractor(images=image, return_tensors="pt") # 모델을 사용한 예측 outputs = model(**inputs)
# 예측 결과 처리 # outputs는 logits와 기타 정보를 포함하므로, 결과를 해석하여 사용자에게 보여줄 형태로 변환 # 여기서는 간단하게 처리합니다. 실제로는 결과를 이미지 위에 박스로 그리는 등의 처리가 필요할 수 있습니다. result = feature_extractor.post_process_object_detection(outputs, threshold=0.9)[0] return result
# Gradio 앱 정의iface = gr.Interface( fn=object_detection, inputs=gr.inputs.Image(type="pil"), outputs=[gr.outputs.Image(type="pil"), gr.outputs.Label(num_top_classes=3)], title="Object Detection with DETR", description="Upload an image and the model will detect objects in the image.")
iface.launch()app.pyAdded+33