Spaces:
Build error
Build error
Commit ·
ce4a8b3
1
Parent(s): 66a7c82
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,34 @@
|
|
| 1 |
import gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
gradio.Interface(
|
| 3 |
fn=predict,
|
| 4 |
inputs="text",
|
|
|
|
| 1 |
import gradio
|
| 2 |
+
import os
|
| 3 |
+
import time
|
| 4 |
+
import csv
|
| 5 |
+
import datetime
|
| 6 |
+
from transformers import RobertaTokenizer, T5ForConditionalGeneration
|
| 7 |
+
|
| 8 |
+
def evaluate(sentence):
|
| 9 |
+
tokenizer = RobertaTokenizer.from_pretrained('Salesforce/codet5-base')
|
| 10 |
+
model = T5ForConditionalGeneration.from_pretrained('Salesforce/codet5-base-multi-sum')
|
| 11 |
+
|
| 12 |
+
# Prepare the input text
|
| 13 |
+
input_text = code_snippet.strip()
|
| 14 |
+
input_ids = tokenizer.encode(input_text, return_tensors='pt')
|
| 15 |
+
# Generate a summary
|
| 16 |
+
generated_ids = model.generate(input_ids, max_length=20)
|
| 17 |
+
summary = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 18 |
+
|
| 19 |
+
return summary
|
| 20 |
+
|
| 21 |
+
def predict(sentence):
|
| 22 |
+
timestamp = datetime.datetime.now().isoformat()
|
| 23 |
+
start_time = time.time()
|
| 24 |
+
predictions = evaluate([sentence])
|
| 25 |
+
elapsed_time = time.time() - start_time
|
| 26 |
+
output = predictions
|
| 27 |
+
print(f"Sentence: {sentence} \nPrediction: {predictions}")
|
| 28 |
+
log_record([sentence, output, timestamp, str(elapsed_time)])
|
| 29 |
+
|
| 30 |
+
return output
|
| 31 |
+
|
| 32 |
gradio.Interface(
|
| 33 |
fn=predict,
|
| 34 |
inputs="text",
|