Spaces:
Build error
Build error
Commit
·
d1231be
1
Parent(s):
ae5bfc1
Update gradio_app.py
Browse files- gradio_app.py +18 -17
gradio_app.py
CHANGED
@@ -8,18 +8,10 @@ from gradio import utils
|
|
8 |
import huggingface_hub
|
9 |
from pathlib import Path
|
10 |
from src.utils.utilities import Utility
|
11 |
-
|
12 |
-
model = BERTClassifier(model_name='jeevavijay10/nlp-goemotions-bert')
|
13 |
-
|
14 |
-
classes = Utility().read_emotion_list()
|
15 |
-
|
16 |
-
hf_token = os.getenv("HF_TOKEN")
|
17 |
|
18 |
dataset_dir = "logs"
|
19 |
-
|
20 |
headers = ["input", "output", "timestamp", "elapsed"]
|
21 |
-
|
22 |
-
|
23 |
repo = huggingface_hub.Repository(
|
24 |
local_dir=dataset_dir,
|
25 |
clone_from="https://huggingface.co/spaces/priyasaravana/CodeSummarization",
|
@@ -38,21 +30,30 @@ def log_record(vals):
|
|
38 |
schedule.run_pending()
|
39 |
print(f"Last Sync: {job.last_run}")
|
40 |
|
41 |
-
def
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
timestamp = datetime.datetime.now().isoformat()
|
44 |
start_time = time.time()
|
45 |
-
predictions =
|
46 |
-
elapsed_time = time.time() - start_time
|
47 |
-
|
48 |
-
output = classes[predictions[0]]
|
49 |
-
|
50 |
print(f"Sentence: {sentence} \nPrediction: {predictions[0]} - {output}")
|
51 |
log_record([sentence, output, timestamp, str(elapsed_time)])
|
52 |
|
53 |
return output
|
54 |
|
55 |
-
|
56 |
def sync_logs():
|
57 |
print(f"Repo Clean: {repo.is_repo_clean()}")
|
58 |
if not repo.is_repo_clean():
|
|
|
8 |
import huggingface_hub
|
9 |
from pathlib import Path
|
10 |
from src.utils.utilities import Utility
|
11 |
+
from transformers import RobertaTokenizer, T5ForConditionalGeneration
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
dataset_dir = "logs"
|
|
|
14 |
headers = ["input", "output", "timestamp", "elapsed"]
|
|
|
|
|
15 |
repo = huggingface_hub.Repository(
|
16 |
local_dir=dataset_dir,
|
17 |
clone_from="https://huggingface.co/spaces/priyasaravana/CodeSummarization",
|
|
|
30 |
schedule.run_pending()
|
31 |
print(f"Last Sync: {job.last_run}")
|
32 |
|
33 |
+
def evaluate(sentence):
|
34 |
+
tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-base')
|
35 |
+
model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-base-multi-sum')
|
36 |
+
|
37 |
+
# Prepare the input text
|
38 |
+
input_text = code_snippet.strip()
|
39 |
+
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
40 |
+
# Generate a summary
|
41 |
+
generated_ids = model.generate(input_ids, max_length=20)
|
42 |
+
summary = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
43 |
+
|
44 |
+
return summary
|
45 |
+
|
46 |
+
def predict(sentence):
|
47 |
timestamp = datetime.datetime.now().isoformat()
|
48 |
start_time = time.time()
|
49 |
+
predictions = evaluate([sentence])
|
50 |
+
elapsed_time = time.time() - start_time
|
51 |
+
output = predictions
|
|
|
|
|
52 |
print(f"Sentence: {sentence} \nPrediction: {predictions[0]} - {output}")
|
53 |
log_record([sentence, output, timestamp, str(elapsed_time)])
|
54 |
|
55 |
return output
|
56 |
|
|
|
57 |
def sync_logs():
|
58 |
print(f"Repo Clean: {repo.is_repo_clean()}")
|
59 |
if not repo.is_repo_clean():
|