Spaces:
Runtime error
Runtime error
Download script.py from yousefabdallah031/efficiency-evaluator: direct link, hf CLI and curl.
- Browser
- Download file 970 Bytes
-
https://huggingface.co/spaces/yousefabdallah031/efficiency-evaluator/resolve/main/script.py
- Command line
-
hf download hf://spaces/yousefabdallah031/efficiency-evaluator/script.py
-
curl -L -o script.py https://huggingface.co/spaces/yousefabdallah031/efficiency-evaluator/resolve/main/script.py
970 Bytes
| import gradio as gr | |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification | |
| import torch | |
| import torch.nn.functional as F | |
| # Load your model | |
| model_path = "best_model_final" | |
| tokenizer = AutoTokenizer.from_pretrained(model_path) | |
| model = AutoModelForSequenceClassification.from_pretrained(model_path) | |
| model.eval() | |
| # Prediction function | |
| def predict_cpu_memory(code): | |
| inputs = tokenizer(code, return_tensors="pt", padding=True, truncation=True) | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| preds = F.sigmoid(outputs.logits).numpy() | |
| cpu_time, memory_usage = preds[0] | |
| return f"CPU Time: {cpu_time:.4f}\nMemory Usage: {memory_usage:.4f}" | |
| # Gradio Interface | |
| iface = gr.Interface( | |
| fn=predict_cpu_memory, | |
| inputs=gr.Textbox(lines=10, placeholder="Paste your code here..."), | |
| outputs="text", | |
| title="Code Resource Usage Predictor" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |