Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546import gradio as grfrom transformers import pipelineimport torchfrom PIL import Image# Load the medical vision-language model# We use bfloat16 to save memory (requires a GPU-enabled Space for best performance)pipe = pipeline("image-text-to-text",model="google/medgemma-4b-it",torch_dtype=torch.bfloat16,device_map="auto")def diagnose_eye(img):if img is None:return "Please upload an image.", ""# Hidden expert promptprompt = "Identify the eye condition in this fundus image. Provide a Diagnosis Label and a bulleted list of suggested Medical Solutions."# Run inferenceresults = pipe(img, prompt=prompt, generate_kwargs={"max_new_tokens": 250})full_text = results[0]['generated_text']# Split text into Label and Solutions for the UIif "Solutions:" in full_text:parts = full_text.split("Solutions:")return parts[0].strip(), parts[1].strip()return full_text, "Consult a specialist for detailed solutions."# Build the Minimalist Interfacedemo = gr.Interface(fn=diagnose_eye,inputs=gr.Image(type="pil", label="Upload Eye Scan"),outputs=[gr.Textbox(label="Diagnosis Label"),gr.Textbox(label="Suggested Solutions")],title="MedGemma Eye Expert",description="Upload a retinal/fundus image for automated medical analysis. Research Use Only.",allow_flagging="never")if __name__ == "__main__":demo.launch(server_name="0.0.0.0", server_port=7860)123456789101112131415import osfrom transformers import pipelineimport torch# This automatically pulls the secret you added in Step 2token = os.environ.get("HF_TOKEN")# Load the model using the token for authenticationpipe = pipeline("image-text-to-text",model="google/medgemma-4b-it",torch_dtype=torch.bfloat16,token=token, # <--- THIS IS THE FIXdevice_map="auto")
app.py+15-46