Spaces:
Sleeping
Sleeping
atifsial123
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -18,23 +18,28 @@ import gradio as gr
|
|
18 |
from transformers import AutoModel, AutoTokenizer
|
19 |
import torch
|
20 |
from sklearn.model_selection import train_test_split
|
21 |
-
from google.colab import files
|
22 |
|
23 |
-
#
|
24 |
-
def
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
return file_path
|
29 |
|
30 |
-
# Load your dataset
|
31 |
-
def load_dataset():
|
32 |
-
|
|
|
33 |
|
34 |
# Check if the file exists
|
35 |
-
if not os.path.exists(file_path):
|
36 |
-
print(f"File not found at '{file_path}',
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
try:
|
40 |
df = pd.read_excel(file_path)
|
@@ -78,8 +83,8 @@ def predict(input_text):
|
|
78 |
return outputs.last_hidden_state
|
79 |
|
80 |
# Build the Gradio interface
|
81 |
-
def build_interface():
|
82 |
-
df = load_dataset() # Load your dataset
|
83 |
if df is None:
|
84 |
return None
|
85 |
|
@@ -95,7 +100,9 @@ def build_interface():
|
|
95 |
|
96 |
# Run the Gradio interface
|
97 |
if __name__ == "__main__":
|
98 |
-
|
|
|
|
|
99 |
if iface:
|
100 |
iface.launch()
|
101 |
else:
|
@@ -103,3 +110,4 @@ if __name__ == "__main__":
|
|
103 |
|
104 |
|
105 |
|
|
|
|
18 |
from transformers import AutoModel, AutoTokenizer
|
19 |
import torch
|
20 |
from sklearn.model_selection import train_test_split
|
|
|
21 |
|
22 |
+
# Function to convert a list to a DataFrame
|
23 |
+
def list_to_dataframe(data_list):
|
24 |
+
# Convert the list to a DataFrame (assuming it's a list of dicts or tuples)
|
25 |
+
df = pd.DataFrame(data_list)
|
26 |
+
return df
|
|
|
27 |
|
28 |
+
# Load your dataset from a file
|
29 |
+
def load_dataset(file_path=None):
|
30 |
+
if file_path is None:
|
31 |
+
file_path = '/content/Valid-part-2.xlsx' # Default path if the file is uploaded manually to Colab
|
32 |
|
33 |
# Check if the file exists
|
34 |
+
if file_path and not os.path.exists(file_path):
|
35 |
+
print(f"File not found at '{file_path}', using default list data...")
|
36 |
+
# Fallback to a default list if file is not found
|
37 |
+
default_data = [
|
38 |
+
{'text': 'Example sentence 1', 'label': 'label1'},
|
39 |
+
{'text': 'Example sentence 2', 'label': 'label2'},
|
40 |
+
# Add more example data as needed
|
41 |
+
]
|
42 |
+
return list_to_dataframe(default_data)
|
43 |
|
44 |
try:
|
45 |
df = pd.read_excel(file_path)
|
|
|
83 |
return outputs.last_hidden_state
|
84 |
|
85 |
# Build the Gradio interface
|
86 |
+
def build_interface(file_path=None):
|
87 |
+
df = load_dataset(file_path) # Load your dataset
|
88 |
if df is None:
|
89 |
return None
|
90 |
|
|
|
100 |
|
101 |
# Run the Gradio interface
|
102 |
if __name__ == "__main__":
|
103 |
+
# You can specify a file_path here if you have a specific file to use
|
104 |
+
file_path = None # Change this to your specific file path if needed
|
105 |
+
iface = build_interface(file_path=file_path)
|
106 |
if iface:
|
107 |
iface.launch()
|
108 |
else:
|
|
|
110 |
|
111 |
|
112 |
|
113 |
+
|