yousefabdallah031 commited on
Commit
a1e35ee
·
verified ·
1 Parent(s): 756c387

Upload 3 files

Browse files
Files changed (3) hide show
  1. PyCharmMiscProject.iml +10 -0
  2. requirements.txt +3 -0
  3. script.py +32 -0
PyCharmMiscProject.iml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="PYTHON_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.venv" />
6
+ </content>
7
+ <orderEntry type="jdk" jdkName="Python 3.13 (PyCharmMiscProject)" jdkType="Python SDK" />
8
+ <orderEntry type="sourceFolder" forTests="false" />
9
+ </component>
10
+ </module>
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio
script.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+ import torch.nn.functional as F
5
+
6
+ # Load your model
7
+ model_path = "best_model_final"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
9
+ model = AutoModelForSequenceClassification.from_pretrained(model_path)
10
+ model.eval()
11
+
12
+ # Prediction function
13
+ def predict_cpu_memory(code):
14
+ inputs = tokenizer(code, return_tensors="pt", padding=True, truncation=True)
15
+
16
+ with torch.no_grad():
17
+ outputs = model(**inputs)
18
+ preds = F.sigmoid(outputs.logits).numpy()
19
+
20
+ cpu_time, memory_usage = preds[0]
21
+ return f"CPU Time: {cpu_time:.4f}\nMemory Usage: {memory_usage:.4f}"
22
+
23
+ # Gradio Interface
24
+ iface = gr.Interface(
25
+ fn=predict_cpu_memory,
26
+ inputs=gr.Textbox(lines=10, placeholder="Paste your code here..."),
27
+ outputs="text",
28
+ title="Code Resource Usage Predictor"
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ iface.launch()