Spaces:
Sleeping
Sleeping
Update app.py
Browse files44 unmodified lines454647484950515253545556573 unmodified lines61626364656667686970718 unmodified lines80818283848586878889909192939495968 unmodified lines10510610710810911011111211311411544 unmodified lineslesion_count = 0for box in result.boxes:# Koordinatlar, sınıf ID ve güven skorlarıx1, y1, x2, y2 = [round(x) for x in box.xyxy[0].tolist()]class_id = int(box.cls[0].item())prob = round(box.conf[0].item(), 2)label = f"{result.names[class_id]}: {prob * 100:.2f}%"# Sınıf sayımıif result.names[class_id] == "Caries":caries_count += 1elif result.names[class_id] == "Deep Caries":3 unmodified lineselif result.names[class_id] == "Periapical Lesion":lesion_count += 1# Kutuları çizdraw.rectangle([x1, y1, x2, y2], outline="red", width=2)draw.text((x1, y1 - 10), label, fill="red")# Tespit mesajını oluşturtespit_mesaji = []if caries_count > 0:tespit_mesaji.append(f"{caries_count} erken çürük tespit edildi.")8 unmodified linestespit_mesaji_str = " ".join(tespit_mesaji)# 4. Chatbot'a Gönderchat_session.history.append({"role": "user", "parts": [tespit_mesaji_str]})response = chat_session.send_message(tespit_mesaji_str)chat_session.history.append({"role": "model", "parts": [response.text]})# Sohbet geçmişini güncellehistory.append({"role": "user", "content": tespit_mesaji_str})history.append({"role": "assistant", "content": response.text})return image, history# 5. Gradio Arayüzüinterface = gr.Blocks()8 unmodified linesresult_image = gr.Image(type="pil", label="Tespit Sonucu")chatbot = gr.Chatbot(label="Sanal Diş Hekimi Chatbot", type="messages")# YOLO ve Chatbot Fonksiyon Bağlantısıdetect_button.click(fn=detect_objects_on_image,inputs=[image_input, chatbot],outputs=[result_image, chatbot])interface.launch()44 unmodified lines45464748495051525354553 unmodified lines5960616263646566678 unmodified lines7677787980818283848586878889909192939495969798991001011021031041051068 unmodified lines11511611711811912012112212312412512612712812913013113213313444 unmodified lineslesion_count = 0for box in result.boxes:x1, y1, x2, y2 = [round(x) for x in box.xyxy[0].tolist()]class_id = int(box.cls[0].item())prob = round(box.conf[0].item(), 2)label = f"{result.names[class_id]}: {prob * 100:.2f}%"if result.names[class_id] == "Caries":caries_count += 1elif result.names[class_id] == "Deep Caries":3 unmodified lineselif result.names[class_id] == "Periapical Lesion":lesion_count += 1draw.rectangle([x1, y1, x2, y2], outline="red", width=2)draw.text((x1, y1 - 10), label, fill="red")tespit_mesaji = []if caries_count > 0:tespit_mesaji.append(f"{caries_count} erken çürük tespit edildi.")8 unmodified linestespit_mesaji_str = " ".join(tespit_mesaji)chat_session.history.append({"role": "user", "parts": [tespit_mesaji_str]})response = chat_session.send_message(tespit_mesaji_str)chat_session.history.append({"role": "model", "parts": [response.text]})history.append({"role": "user", "content": tespit_mesaji_str})history.append({"role": "assistant", "content": response.text})return image, history# 4. Kullanıcı Mesajını İşleyen Fonksiyondef send_user_message(user_message, history):if user_message.strip() == "":return historychat_session.history.append({"role": "user", "parts": [user_message]})response = chat_session.send_message(user_message)chat_session.history.append({"role": "model", "parts": [response.text]})history.append({"role": "user", "content": user_message})history.append({"role": "assistant", "content": response.text})return history# 5. Gradio Arayüzüinterface = gr.Blocks()8 unmodified linesresult_image = gr.Image(type="pil", label="Tespit Sonucu")chatbot = gr.Chatbot(label="Sanal Diş Hekimi Chatbot", type="messages")with gr.Row():user_input = gr.Textbox(label="Mesajınızı Yazın")send_button = gr.Button("Gönder")detect_button.click(fn=detect_objects_on_image,inputs=[image_input, chatbot],outputs=[result_image, chatbot])send_button.click(fn=send_user_message,inputs=[user_input, chatbot],outputs=[chatbot])interface.launch()
app.py+26-7