Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,6 @@ import numpy as np
|
|
| 6 |
from PIL import Image
|
| 7 |
from transformers import AutoProcessor, VisionEncoderDecoderModel, AutoModelForImageTextToText
|
| 8 |
import torch
|
| 9 |
-
# Suppress PyTorch Dynamo compilation errors
|
| 10 |
-
import torch._dynamo
|
| 11 |
-
torch._dynamo.config.suppress_errors = True
|
| 12 |
try:
|
| 13 |
from sentence_transformers import SentenceTransformer
|
| 14 |
import numpy as np
|
|
@@ -248,23 +245,13 @@ Provide a descriptive alt text in 1-2 sentences that is informative but not over
|
|
| 248 |
input_len = input_ids["input_ids"].shape[-1]
|
| 249 |
|
| 250 |
input_ids = input_ids.to(self.model.device, dtype=self.model.dtype)
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
do_sample=True,
|
| 259 |
-
temperature=0.1,
|
| 260 |
-
top_p=0.9,
|
| 261 |
-
top_k=50,
|
| 262 |
-
num_beams=1,
|
| 263 |
-
pad_token_id=self.processor.tokenizer.pad_token_id,
|
| 264 |
-
eos_token_id=self.processor.tokenizer.eos_token_id,
|
| 265 |
-
repetition_penalty=1.05,
|
| 266 |
-
use_cache=True
|
| 267 |
-
)
|
| 268 |
|
| 269 |
text = self.processor.batch_decode(
|
| 270 |
outputs[:, input_len:],
|
|
@@ -272,8 +259,7 @@ Provide a descriptive alt text in 1-2 sentences that is informative but not over
|
|
| 272 |
clean_up_tokenization_spaces=True
|
| 273 |
)
|
| 274 |
|
| 275 |
-
|
| 276 |
-
return result if result else "I apologize, but I couldn't generate a proper response. Please try rephrasing your question."
|
| 277 |
|
| 278 |
except Exception as e:
|
| 279 |
print(f"❌ Error in chat: {e}")
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
from transformers import AutoProcessor, VisionEncoderDecoderModel, AutoModelForImageTextToText
|
| 8 |
import torch
|
|
|
|
|
|
|
|
|
|
| 9 |
try:
|
| 10 |
from sentence_transformers import SentenceTransformer
|
| 11 |
import numpy as np
|
|
|
|
| 245 |
input_len = input_ids["input_ids"].shape[-1]
|
| 246 |
|
| 247 |
input_ids = input_ids.to(self.model.device, dtype=self.model.dtype)
|
| 248 |
+
outputs = self.model.generate(
|
| 249 |
+
**input_ids,
|
| 250 |
+
max_new_tokens=1024,
|
| 251 |
+
disable_compile=True,
|
| 252 |
+
do_sample=True,
|
| 253 |
+
temperature=0.7
|
| 254 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
text = self.processor.batch_decode(
|
| 257 |
outputs[:, input_len:],
|
|
|
|
| 259 |
clean_up_tokenization_spaces=True
|
| 260 |
)
|
| 261 |
|
| 262 |
+
return text[0].strip()
|
|
|
|
| 263 |
|
| 264 |
except Exception as e:
|
| 265 |
print(f"❌ Error in chat: {e}")
|