Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import logging
|
|
| 4 |
import numpy as np
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
import torch
|
| 7 |
-
from torch.
|
| 8 |
from spaces import GPU
|
| 9 |
import json # Import json for direct JSON output in UI
|
| 10 |
|
|
@@ -51,7 +51,7 @@ def generate_embedding(text, focus):
|
|
| 51 |
initialize_model()
|
| 52 |
|
| 53 |
try:
|
| 54 |
-
with autocast(
|
| 55 |
embedding_vector = model.encode([text])[0].tolist() # Get embedding as list
|
| 56 |
# Convert embedding to JSON string for direct display in UI
|
| 57 |
embedding_json_str = json.dumps(embedding_vector)
|
|
@@ -98,7 +98,7 @@ def process_files(files, focus):
|
|
| 98 |
try:
|
| 99 |
with open(file.name, 'r') as f:
|
| 100 |
text = f.read()
|
| 101 |
-
with autocast(
|
| 102 |
embedding = model.encode([text])[0].tolist()
|
| 103 |
all_embeddings.append(embedding)
|
| 104 |
file_statuses.append(f"File '{file.name}' processed successfully.")
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
import torch
|
| 7 |
+
from torch.amp import autocast # Corrected import for autocast
|
| 8 |
from spaces import GPU
|
| 9 |
import json # Import json for direct JSON output in UI
|
| 10 |
|
|
|
|
| 51 |
initialize_model()
|
| 52 |
|
| 53 |
try:
|
| 54 |
+
with torch.amp.autocast('cuda'): # Corrected autocast usage
|
| 55 |
embedding_vector = model.encode([text])[0].tolist() # Get embedding as list
|
| 56 |
# Convert embedding to JSON string for direct display in UI
|
| 57 |
embedding_json_str = json.dumps(embedding_vector)
|
|
|
|
| 98 |
try:
|
| 99 |
with open(file.name, 'r') as f:
|
| 100 |
text = f.read()
|
| 101 |
+
with torch.amp.autocast('cuda'): # Corrected autocast usage
|
| 102 |
embedding = model.encode([text])[0].tolist()
|
| 103 |
all_embeddings.append(embedding)
|
| 104 |
file_statuses.append(f"File '{file.name}' processed successfully.")
|