Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,18 @@ from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
|
|
| 4 |
# Available models for code explanation
|
| 5 |
MODELS = {
|
| 6 |
"CodeT5-small-sum": "Salesforce/codet5-small",
|
| 7 |
-
"CodeT5-base-sum": "Salesforce/codet5-base-multi-sum"
|
| 8 |
-
"CodeBERTa": "huggingface/CodeBERTa-small-v1"
|
| 9 |
}
|
| 10 |
|
| 11 |
def load_model(model_name):
|
| 12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
-
|
| 14 |
-
# Use summarization for CodeT5, text2text-generation for others
|
| 15 |
if "codet5" in model_name.lower():
|
|
|
|
| 16 |
return pipeline("summarization", model=model, tokenizer=tokenizer)
|
| 17 |
else:
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
def explain_code(files, model_choice):
|
| 21 |
model_id = MODELS[model_choice]
|
|
|
|
| 4 |
# Available models for code explanation
|
| 5 |
MODELS = {
|
| 6 |
"CodeT5-small-sum": "Salesforce/codet5-small",
|
| 7 |
+
"CodeT5-base-sum": "Salesforce/codet5-base-multi-sum"
|
|
|
|
| 8 |
}
|
| 9 |
|
| 10 |
def load_model(model_name):
|
| 11 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 12 |
+
# Use T5 for Seq2Seq, fallback to text2text-generation for others
|
|
|
|
| 13 |
if "codet5" in model_name.lower():
|
| 14 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 15 |
return pipeline("summarization", model=model, tokenizer=tokenizer)
|
| 16 |
else:
|
| 17 |
+
# fallback for unsupported models
|
| 18 |
+
return pipeline("text2text-generation", model=model_name, tokenizer=tokenizer)
|
| 19 |
|
| 20 |
def explain_code(files, model_choice):
|
| 21 |
model_id = MODELS[model_choice]
|