Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819import osimport torchfrom transformers import pipeline, BitsAndBytesConfigtoken = os.environ.get("HF_TOKEN")# This config shrinks the model so it fits on free hardwarequant_config = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_compute_dtype=torch.bfloat16)pipe = pipeline("image-text-to-text",model="google/medgemma-4b-it",model_kwargs={"quantization_config": quant_config}, # <--- Use 4-bit quantizationtoken=token,device_map="auto")1234567891011121314151617181920212223242526272829303132333435import osimport torchimport gradio as grfrom transformers import pipeline, BitsAndBytesConfig# 1. Get Tokentoken = os.environ.get("HF_TOKEN")# 2. Configure 4-bit loading (Essential for 16GB RAM)quant_config = BitsAndBytesConfig(load_in_4bit=True,bnb_4bit_compute_dtype=torch.float16)# 3. Load Model with Quantization# Note: Even on CPU, bitsandbytes helps manage the weight loadingpipe = pipeline("image-text-to-text",model="google/medgemma-4b-it",model_kwargs={"quantization_config": quant_config},token=token,device_map="auto")def diagnose(img):if img is None: return "Upload image", ""result = pipe(img, prompt="Diagnose this eye image and give solutions.")return result[0]['generated_text']# 4. Launch with explicit Port/Hostdemo = gr.Interface(fn=diagnose, inputs=gr.Image(type="pil"), outputs="text")if __name__ == "__main__":# 0.0.0.0 and 7860 are REQUIRED for Hugging Face Spacesdemo.launch(server_name="0.0.0.0", server_port=7860)
app.py+20-4