Spaces:
Sleeping
Sleeping
Update app.py
Browse files18 unmodified lines1920212223242526272829303132333435363738394041424344454647484918 unmodified lines]# Inference functiondef generate_caption(image):if image.mode != "RGB":image = image.convert("RGB")# Preprocess the image and generate a captioninputs = processor(image, return_tensors="pt").to(device, torch.float16)output = model.generate(**inputs, max_new_tokens=50)caption = processor.decode(output[0], skip_special_tokens=True)# Filter the caption to only include construction-related termsfiltered_caption = " ".join([word for word in caption.split() if word.lower() in construction_terms])# If no construction-related terms are found, return a default messageif not filtered_caption:filtered_caption = "No construction-related activities detected."return filtered_caption# Gradio interfaceiface = gr.Interface(fn=generate_caption,inputs=gr.Image(type="pil"),outputs="text",title="Construction Site Image-to-Text Generator",description="Upload a site photo. The model will detect and describe construction activities and materials (e.g., concrete pouring, scaffolding, steel rods).")iface.launch()18 unmodified lines1920212223242526272829303132333435363738394041424344454647484950515253545518 unmodified lines]# Inference functiondef generate_captions(images):captions = []for image in images:if image.mode != "RGB":image = image.convert("RGB")# Preprocess the image and generate a captioninputs = processor(image, return_tensors="pt").to(device, torch.float16)output = model.generate(**inputs, max_new_tokens=50)caption = processor.decode(output[0], skip_special_tokens=True)# Filter the caption to only include construction-related termsfiltered_caption = " ".join([word for word in caption.split() if word.lower() in construction_terms])# If no construction-related terms are found, return a default messageif not filtered_caption:filtered_caption = "No construction-related activities detected."captions.append(filtered_caption)return captions# Gradio interfaceiface = gr.Interface(fn=generate_captions,inputs=gr.Image(type="pil", tool="editor", label="Upload Site Photos", multiple=True),outputs="text",title="Construction Site Image-to-Text Generator",description="Upload up to 10 site photos. The model will detect and describe construction activities and materials (e.g., concrete pouring, scaffolding, steel rods).",allow_flagging="never")iface.launch()
app.py+23-17