Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from fastai.text.all import *
|
| 4 |
+
import warnings
|
| 5 |
+
warnings.filterwarnings('ignore')
|
| 6 |
+
|
| 7 |
+
print("Current directory files:", os.listdir('.'))
|
| 8 |
+
|
| 9 |
+
# Try to load model
|
| 10 |
+
try:
|
| 11 |
+
learn = load_learner('js_concept_tagger_simple_numbers.pkl')
|
| 12 |
+
print("✅ Model loaded successfully!")
|
| 13 |
+
except Exception as e:
|
| 14 |
+
print(f"❌ Model loading failed: {e}")
|
| 15 |
+
learn = None
|
| 16 |
+
|
| 17 |
+
def predict_js_concept(code_snippet):
|
| 18 |
+
if learn is None:
|
| 19 |
+
return "❌ Model not available - check logs", 0.0, "Model loading failed"
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
pred, pred_idx, probs = learn.predict(code_snippet)
|
| 23 |
+
predicted_concept = str(pred)
|
| 24 |
+
confidence = float(probs.max())
|
| 25 |
+
return predicted_concept, confidence, f"Success! Predicted: {predicted_concept}"
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Prediction error: {str(e)}", 0.0, "Prediction failed"
|
| 28 |
+
|
| 29 |
+
# Simple interface
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=predict_js_concept,
|
| 32 |
+
inputs=gr.Textbox(label="JavaScript Code", lines=3),
|
| 33 |
+
outputs=[
|
| 34 |
+
gr.Textbox(label="Prediction"),
|
| 35 |
+
gr.Number(label="Confidence"),
|
| 36 |
+
gr.Textbox(label="Status")
|
| 37 |
+
],
|
| 38 |
+
title="JS Concept Classifier",
|
| 39 |
+
examples=[["const age = 25;"]]
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
demo.launch()
|