| # import gradio as gr | |
| # from segmentation import segment_image | |
| # import numpy as np | |
| # import cv2 | |
| # # Image de test par défaut | |
| # default_image_path = "./image.png" | |
| # def segment_and_display(image_path=default_image_path): | |
| # # Appeler la fonction de segmentation | |
| # original_image, segmented_image = segment_image(image_path) | |
| # # Retourner les images pour l'affichage | |
| # return original_image, segmented_image | |
| # # Charger l'image de test par défaut | |
| # default_original_image, default_segmented_image = segment_image(default_image_path) | |
| # # Interface Gradio | |
| # iface = gr.Interface( | |
| # fn=segment_and_display, | |
| # inputs=gr.Image(type="filepath", label="Upload Image"), | |
| # outputs=[ | |
| # gr.Image(type="numpy", label="Original Image"), | |
| # gr.Image(type="numpy", label="Segmented Image") | |
| # ], | |
| # title="Image Segmentation with K-means (k=2)", | |
| # description="Upload an image or use the default test image to see the segmentation result.", | |
| # examples=[ | |
| # [default_image_path] | |
| # ], | |
| # live=True # Permet de voir les changements en temps réel | |
| # ) | |
| # # Afficher l'image de test par défaut lorsque l'interface est ouverte | |
| # iface.launch(share=True, inline=True) | |
| import gradio as gr | |
| from segmentation import segment_image | |
| from medgemma_api import query_medgemma | |
| import os | |
| # 默认图片路径 | |
| default_image_path = "./image.png" | |
| def segment_only(image_path): | |
| _, segmented_image = segment_image(image_path) | |
| return segmented_image | |
| def analyze_with_medgemma(image, question): | |
| return query_medgemma(image, question) | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| image_input = gr.Image(type="filepath", label="Upload Image") | |
| segmented_output = gr.Image(type="numpy", label="Segmented Image") | |
| image_input.change(fn=segment_only, inputs=image_input, outputs=segmented_output) | |
| with gr.Column(scale=2): | |
| chatbot = gr.Textbox(label="Ask MedGemma", placeholder="Enter your medical question...") | |
| image_for_analysis = gr.Image(type="filepath", label="Upload image for analysis (optional)") | |
| analyze_button = gr.Button("Analyze") | |
| response_output = gr.Textbox(label="Response") | |
| analyze_button.click(fn=analyze_with_medgemma, inputs=[image_for_analysis, chatbot], outputs=response_output) | |
| demo.launch() | |