Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,15 +2,22 @@ import gradio as gr
|
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
import pandas as pd
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
# Load your data from the CSV file
|
| 6 |
data_file = "train_1.csv" # Replace with your CSV file name
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Assuming your CSV has a column named 'text' with the data
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
# Precompute embeddings
|
| 16 |
embeddings = model.encode(data, convert_to_tensor=True)
|
|
|
|
| 2 |
from sentence_transformers import SentenceTransformer, util
|
| 3 |
import pandas as pd
|
| 4 |
|
| 5 |
+
# Pre-download the model to avoid runtime errors
|
| 6 |
+
model_name = "sentence-transformers/all-MiniLM-L6-v2"
|
| 7 |
+
model = SentenceTransformer(model_name)
|
| 8 |
+
|
| 9 |
# Load your data from the CSV file
|
| 10 |
data_file = "train_1.csv" # Replace with your CSV file name
|
| 11 |
+
try:
|
| 12 |
+
df = pd.read_csv(data_file, nrows=1000) # Load only the first 1000 rows for testing
|
| 13 |
+
except FileNotFoundError:
|
| 14 |
+
df = pd.DataFrame({"text": ["Sample data 1", "Sample data 2", "Sample data 3"]}) # Fallback sample data
|
| 15 |
|
| 16 |
# Assuming your CSV has a column named 'text' with the data
|
| 17 |
+
if "text" in df.columns:
|
| 18 |
+
data = df['text'].dropna().tolist()
|
| 19 |
+
else:
|
| 20 |
+
data = ["Sample data 1", "Sample data 2", "Sample data 3"] # Fallback if no 'text' column
|
| 21 |
|
| 22 |
# Precompute embeddings
|
| 23 |
embeddings = model.encode(data, convert_to_tensor=True)
|