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