Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,87 +1,99 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
# Define a function that takes a text input and returns the result
|
8 |
-
def analyze_text(input):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
param_model_name="CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth"
|
14 |
-
|
15 |
-
tokenizer = AutoTokenizer.from_pretrained(param_model_name)
|
16 |
-
|
17 |
-
class BertForSTS(torch.nn.Module):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
#
|
56 |
-
#
|
57 |
-
|
58 |
-
#
|
59 |
-
|
60 |
-
#
|
61 |
-
#
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
model
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
#
|
80 |
-
iface = gr.Interface(
|
81 |
-
fn=analyze_text, # The function to be called with user input
|
82 |
-
inputs=[gr.Textbox(), gr.Textbox()],
|
83 |
-
outputs="text" # Display the result as text
|
84 |
-
)
|
85 |
-
|
86 |
-
# # Launch the Gradio interface
|
87 |
-
iface.launch()
|
|
|
1 |
+
from pydrive.auth import GoogleAuth
|
2 |
+
from pydrive.drive import GoogleDrive
|
3 |
+
|
4 |
+
# Authenticate and create the PyDrive client.
|
5 |
+
gauth = GoogleAuth()
|
6 |
+
gauth.LocalWebserverAuth()
|
7 |
+
drive = GoogleDrive(gauth)
|
8 |
+
|
9 |
+
# Replace 'file_id' with the actual ID of your file in Google Drive.
|
10 |
+
file_id = '1lDfR_B3fYM_rmC8H_HDtRdxJKveYWmOp'
|
11 |
+
|
12 |
+
# Create a GoogleDriveFile instance with the file ID.
|
13 |
+
file_obj = drive.CreateFile({'id': file_id})
|
14 |
+
|
15 |
+
# Download the file content.
|
16 |
+
downloaded_file_path = 'downloaded_model.pth'
|
17 |
+
file_obj.GetContentFile(downloaded_file_path)
|
18 |
+
|
19 |
+
print("ok")
|
20 |
+
|
21 |
+
# import gradio as gr
|
22 |
+
# from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
23 |
+
# import torch
|
24 |
+
# from sentence_transformers import SentenceTransformer, models
|
25 |
+
# param_max_length=256
|
26 |
|
27 |
+
# # Define a function that takes a text input and returns the result
|
28 |
+
# def analyze_text(input):
|
29 |
+
# # Your processing or model inference code here
|
30 |
+
# result = predict_similarity(input)
|
31 |
+
# return result
|
32 |
+
|
33 |
+
# param_model_name="CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth"
|
34 |
+
|
35 |
+
# tokenizer = AutoTokenizer.from_pretrained(param_model_name)
|
36 |
+
|
37 |
+
# class BertForSTS(torch.nn.Module):
|
38 |
+
|
39 |
+
# def __init__(self):
|
40 |
+
# super(BertForSTS, self).__init__()
|
41 |
+
# #self.bert = models.Transformer('bert-base-uncased', max_seq_length=128)
|
42 |
+
# #self.bert = AutoModelForSequenceClassification.from_pretrained("CAMeL-Lab/bert-base-arabic-camelbert-msa-sixteenth")
|
43 |
+
# self.bert = models.Transformer(param_model_name, max_seq_length=param_max_length)
|
44 |
+
|
45 |
+
|
46 |
+
# dimension= self.bert.get_word_embedding_dimension()
|
47 |
+
# #print(dimension)
|
48 |
+
# self.pooling_layer = models.Pooling(dimension)
|
49 |
+
# self.dropout = torch.nn.Dropout(0.1)
|
50 |
+
|
51 |
+
# # relu activation function
|
52 |
+
# self.relu = torch.nn.ReLU()
|
53 |
+
|
54 |
+
# # dense layer 1
|
55 |
+
# self.fc1 = torch.nn.Linear(dimension,512)
|
56 |
+
|
57 |
+
# # dense layer 2 (Output layer)
|
58 |
+
# self.fc2 = torch.nn.Linear(512,512)
|
59 |
+
# #self.pooling_layer = models.Pooling(self.bert.config.hidden_size)
|
60 |
+
# self.sts_bert = SentenceTransformer(modules=[self.bert,self.pooling_layer, self.fc1])
|
61 |
+
# #self.sts_bert = SentenceTransformer(modules=[self.bert,self.pooling_layer, self.fc1, self.relu, self.dropout,self.fc2])
|
62 |
+
# def forward(self, input_data):
|
63 |
+
# #print(input_data)
|
64 |
+
# x=self.bert(input_data)
|
65 |
+
# x=self.pooling_layer(x)
|
66 |
+
# x=self.fc1(x['sentence_embedding'])
|
67 |
+
# x = self.relu(x)
|
68 |
+
# x = self.dropout(x)
|
69 |
+
# #x = self.fc2(x)
|
70 |
+
|
71 |
+
# return x
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
# model_load_path = "model.pt"
|
76 |
+
# model = BertForSTS()
|
77 |
+
# model.load_state_dict(torch.load(model_load_path))
|
78 |
+
# model.to(device)
|
79 |
+
|
80 |
+
# def predict_similarity(sentence_pair):
|
81 |
+
# test_input = tokenizer(sentence_pair, padding='max_length', max_length = param_max_length, truncation=True, return_tensors="pt").to(device)
|
82 |
+
# test_input['input_ids'] = test_input['input_ids']
|
83 |
+
# print(test_input['input_ids'])
|
84 |
+
# test_input['attention_mask'] = test_input['attention_mask']
|
85 |
+
# del test_input['token_type_ids']
|
86 |
+
# output = model(test_input)
|
87 |
+
# sim = torch.nn.functional.cosine_similarity(output[0], output[1], dim=0).item()*2-1
|
88 |
+
|
89 |
+
# return sim
|
90 |
+
|
91 |
+
# # Create a Gradio interface with a text input zone
|
92 |
+
# iface = gr.Interface(
|
93 |
+
# fn=analyze_text, # The function to be called with user input
|
94 |
+
# inputs=[gr.Textbox(), gr.Textbox()],
|
95 |
+
# outputs="text" # Display the result as text
|
96 |
+
# )
|
97 |
+
|
98 |
+
# # # Launch the Gradio interface
|
99 |
+
# iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|