DINGOLANI commited on
Commit
b718343
·
verified ·
1 Parent(s): b0b08e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
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
- df = pd.read_csv(data_file)
 
 
 
8
 
9
  # Assuming your CSV has a column named 'text' with the data
10
- data = df['text'].tolist()
11
-
12
- # Load the SentenceTransformer model
13
- model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
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)