Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,13 +4,23 @@ from PIL import Image
|
|
4 |
import requests
|
5 |
import torch
|
6 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Initialize the model and processor
|
9 |
model_id = "google/gemma-3n-e4b-it"
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
def process_inputs(image_input, image_url, text_prompt):
|
16 |
"""
|
@@ -88,8 +98,8 @@ iface = gr.Interface(
|
|
88 |
gr.Textbox(label="Text Prompt", placeholder="Enter your prompt here")
|
89 |
],
|
90 |
outputs=gr.Textbox(label="Model Response"),
|
91 |
-
title="Gemma-3 Multimodal App",
|
92 |
-
description="Upload an image or provide an image URL, and enter a text prompt to interact with the Gemma-3 model.
|
93 |
allow_flagging="never"
|
94 |
)
|
95 |
|
|
|
4 |
import requests
|
5 |
import torch
|
6 |
import io
|
7 |
+
from huggingface_hub import login
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
hf_token = os.environ.get("HF_TOKEN")
|
12 |
+
login(token=hf_token)
|
13 |
+
|
14 |
|
15 |
# Initialize the model and processor
|
16 |
model_id = "google/gemma-3n-e4b-it"
|
17 |
+
try:
|
18 |
+
model = Gemma3nForConditionalGeneration.from_pretrained(
|
19 |
+
model_id, device_map="auto", torch_dtype=torch.bfloat16
|
20 |
+
).eval()
|
21 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
22 |
+
except Exception as e:
|
23 |
+
raise Exception(f"Failed to load model or processor: {str(e)}")
|
24 |
|
25 |
def process_inputs(image_input, image_url, text_prompt):
|
26 |
"""
|
|
|
98 |
gr.Textbox(label="Text Prompt", placeholder="Enter your prompt here")
|
99 |
],
|
100 |
outputs=gr.Textbox(label="Model Response"),
|
101 |
+
title="Gemma-3 Multimodal App (Authenticated)",
|
102 |
+
description="Upload an image or provide an image URL, and enter a text prompt to interact with the Gemma-3 model. Ensure you have authenticated with a valid Hugging Face access token.",
|
103 |
allow_flagging="never"
|
104 |
)
|
105 |
|