Spaces:
Running
on
Zero
Running
on
Zero
backup
Browse files
app.py
CHANGED
@@ -29,7 +29,7 @@ login(token=os.environ["HF_TOKEN"])
|
|
29 |
|
30 |
# Load model and processor (do this outside the inference function to avoid reloading)
|
31 |
base_model_path = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
32 |
-
lora_weights_path = "taesiri/
|
33 |
|
34 |
processor = AutoProcessor.from_pretrained(base_model_path)
|
35 |
model = MllamaForConditionalGeneration.from_pretrained(
|
@@ -48,10 +48,7 @@ def parse_json_response(json_str):
|
|
48 |
|
49 |
try:
|
50 |
# Debug original input
|
51 |
-
print(
|
52 |
-
"DEBUG: Raw JSON input:",
|
53 |
-
json_str[:200] + "..." if len(json_str) > 200 else json_str,
|
54 |
-
)
|
55 |
|
56 |
# Handle potential JSON string escaping
|
57 |
json_str = json_str.strip()
|
@@ -59,17 +56,11 @@ def parse_json_response(json_str):
|
|
59 |
print("DEBUG: Removing outer quotes")
|
60 |
json_str = json_str[1:-1]
|
61 |
|
|
|
62 |
first_parse = json.loads(json_str)
|
63 |
print("DEBUG: First parse result type:", type(first_parse))
|
64 |
-
print(
|
65 |
-
"DEBUG: First parse content:",
|
66 |
-
(
|
67 |
-
str(first_parse)[:200] + "..."
|
68 |
-
if len(str(first_parse)) > 200
|
69 |
-
else str(first_parse)
|
70 |
-
),
|
71 |
-
)
|
72 |
|
|
|
73 |
json_object = (
|
74 |
json.loads(first_parse) if isinstance(first_parse, str) else first_parse
|
75 |
)
|
@@ -178,17 +169,11 @@ def inference(image):
|
|
178 |
|
179 |
# Decode output
|
180 |
result = processor.decode(output[0], skip_special_tokens=True)
|
181 |
-
print(
|
182 |
-
"DEBUG: Full decoded output:",
|
183 |
-
result[:200] + "..." if len(result) > 200 else result,
|
184 |
-
)
|
185 |
|
186 |
try:
|
187 |
json_str = result.strip().split("assistant\n")[1].strip()
|
188 |
-
print(
|
189 |
-
"DEBUG: Extracted JSON string after split:",
|
190 |
-
json_str[:200] + "..." if len(json_str) > 200 else json_str,
|
191 |
-
)
|
192 |
except Exception as e:
|
193 |
print("DEBUG: Error splitting response:", e)
|
194 |
return ["Error extracting JSON from response"] * 8 + [
|
@@ -224,7 +209,7 @@ def inference(image):
|
|
224 |
|
225 |
# Update Gradio interface
|
226 |
with gr.Blocks() as demo:
|
227 |
-
gr.Markdown("#
|
228 |
|
229 |
with gr.Row():
|
230 |
with gr.Column(scale=1):
|
|
|
29 |
|
30 |
# Load model and processor (do this outside the inference function to avoid reloading)
|
31 |
base_model_path = "meta-llama/Llama-3.2-11B-Vision-Instruct"
|
32 |
+
lora_weights_path = "taesiri/BugsBunny-LLama-3.2-11B-Vision-Instruct-Medium"
|
33 |
|
34 |
processor = AutoProcessor.from_pretrained(base_model_path)
|
35 |
model = MllamaForConditionalGeneration.from_pretrained(
|
|
|
48 |
|
49 |
try:
|
50 |
# Debug original input
|
51 |
+
print("DEBUG: Raw JSON input:", json_str)
|
|
|
|
|
|
|
52 |
|
53 |
# Handle potential JSON string escaping
|
54 |
json_str = json_str.strip()
|
|
|
56 |
print("DEBUG: Removing outer quotes")
|
57 |
json_str = json_str[1:-1]
|
58 |
|
59 |
+
# First parse - handles the outer JSON encoding
|
60 |
first_parse = json.loads(json_str)
|
61 |
print("DEBUG: First parse result type:", type(first_parse))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
# Second parse - if the result is still a string, parse again
|
64 |
json_object = (
|
65 |
json.loads(first_parse) if isinstance(first_parse, str) else first_parse
|
66 |
)
|
|
|
169 |
|
170 |
# Decode output
|
171 |
result = processor.decode(output[0], skip_special_tokens=True)
|
172 |
+
print("DEBUG: Full decoded output:", result)
|
|
|
|
|
|
|
173 |
|
174 |
try:
|
175 |
json_str = result.strip().split("assistant\n")[1].strip()
|
176 |
+
print("DEBUG: Extracted JSON string after split:", json_str)
|
|
|
|
|
|
|
177 |
except Exception as e:
|
178 |
print("DEBUG: Error splitting response:", e)
|
179 |
return ["Error extracting JSON from response"] * 8 + [
|
|
|
209 |
|
210 |
# Update Gradio interface
|
211 |
with gr.Blocks() as demo:
|
212 |
+
gr.Markdown("# BugsBunny-LLama-3.2-11B-Base-Medium Demo")
|
213 |
|
214 |
with gr.Row():
|
215 |
with gr.Column(scale=1):
|