Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line2345656783 unmodified lines12131416151617182019202122232526272829242526272829303131323333343536373839383940414243441 unmodified lineimport gradio as grfrom huggingface_hub import InferenceClient
# 1. Initialize the Client with your token# Make sure HF_TOKEN is in your Space's 'Secrets'# 1. Initialize the Client using your HF_TOKEN secretclient = InferenceClient( model="google/medgemma-4b-it", token=os.environ.get("HF_TOKEN")3 unmodified lines if img is None: return "Please upload an image." # Hidden expert prompt # Detailed instruction for the medical model prompt = "Identify the eye disease in this retinal scan and provide suggested solutions." try: # The new client handles the API call and image encoding automatically # Calls the model via Hugging Face's serverless infrastructure response = client.visual_question_answering( image=img, question=prompt ) # Note: MedGemma might return different formats; # usually it's a direct string or a list of answers. if isinstance(response, list): return response[0]['answer'] return response # Format the response clearly if isinstance(response, list) and len(response) > 0: return response[0].get('answer', "No clear diagnosis found.") return str(response) except Exception as e: return f"Error connecting to MedGemma: {str(e)}" return f"Error: {str(e)}. Ensure you have accepted the MedGemma license on Hugging Face."
# Minimalist Interface# 2. Build the Interfacedemo = gr.Interface( fn=diagnose, inputs=gr.Image(type="pil", label="Upload Eye Scan"), outputs=gr.Textbox(label="Diagnosis & Solutions"), title="MedGemma Eye Expert", description="Automated analysis via title="👁️ Eye Disease Detector", description="Upload a fundus/retinal image for automated analysis powered by MedGemma 4B.")
if __name__ == "__main__": # ssr_mode=False avoids the 'Invalid file descriptor' error demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)app.py+18-13