Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,7 @@ import ast
|
|
3 |
import streamlit.components.v1 as components
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
# ---
|
7 |
-
st.set_page_config(page_title="AR/VR Enhanced Code Learning", layout="wide")
|
8 |
-
st.title("π AR/VR Enhanced Code Visualizer")
|
9 |
-
|
10 |
-
# --- File upload ---
|
11 |
-
uploaded_file = st.file_uploader("Upload your Python file", type=["py"])
|
12 |
-
|
13 |
-
# --- Hugging Face model ---
|
14 |
@st.cache_resource
|
15 |
def load_model():
|
16 |
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
@@ -18,33 +11,42 @@ def load_model():
|
|
18 |
|
19 |
summarizer = load_model()
|
20 |
|
21 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
if uploaded_file is not None:
|
23 |
code = uploaded_file.read().decode('utf-8')
|
24 |
st.subheader("π Uploaded Code")
|
25 |
st.code(code, language='python')
|
26 |
|
27 |
-
# ---
|
28 |
tree = ast.parse(code)
|
29 |
functions = [node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)]
|
30 |
classes = [node.name for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
|
31 |
|
32 |
-
st.subheader("
|
33 |
-
st.write(f"**Functions:** {functions}")
|
34 |
-
st.write(f"**Classes:** {classes}")
|
35 |
|
36 |
# --- Hugging Face Summary ---
|
37 |
-
st.subheader("π§
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
49 |
components.iframe(aframe_url, height=500)
|
50 |
|
|
|
|
|
|
3 |
import streamlit.components.v1 as components
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# --- Hugging Face summarization model ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
@st.cache_resource
|
8 |
def load_model():
|
9 |
summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
|
|
|
11 |
|
12 |
summarizer = load_model()
|
13 |
|
14 |
+
# --- Streamlit page config ---
|
15 |
+
st.set_page_config(page_title="AR/VR Code Visualizer", layout="wide")
|
16 |
+
st.title("π AR/VR Enhanced Code Visualizer")
|
17 |
+
|
18 |
+
# --- File uploader ---
|
19 |
+
uploaded_file = st.file_uploader("π Upload your Python file", type=["py"])
|
20 |
+
|
21 |
if uploaded_file is not None:
|
22 |
code = uploaded_file.read().decode('utf-8')
|
23 |
st.subheader("π Uploaded Code")
|
24 |
st.code(code, language='python')
|
25 |
|
26 |
+
# --- AST Parsing ---
|
27 |
tree = ast.parse(code)
|
28 |
functions = [node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)]
|
29 |
classes = [node.name for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
|
30 |
|
31 |
+
st.subheader("π Detected Elements")
|
32 |
+
st.write(f"**Functions:** {functions if functions else 'None found'}")
|
33 |
+
st.write(f"**Classes:** {classes if classes else 'None found'}")
|
34 |
|
35 |
# --- Hugging Face Summary ---
|
36 |
+
st.subheader("π§ Code Explanation")
|
37 |
+
prompt = f"This Python code has functions: {functions} and classes: {classes}. Explain what the code might be doing."
|
38 |
+
try:
|
39 |
+
summary = summarizer(prompt, max_length=60, min_length=15, do_sample=False)
|
40 |
+
st.success(summary[0]['summary_text'])
|
41 |
+
except Exception as e:
|
42 |
+
st.error(f"Summarization failed: {e}")
|
43 |
+
|
44 |
+
# --- AR/VR Scene ---
|
45 |
+
st.subheader("π AR/VR Visualization")
|
46 |
+
st.info("Below is a sample 3D scene visualizing code elements. Dynamic visual generation coming soon!")
|
47 |
+
|
48 |
+
aframe_url = "https://your-username.github.io/ar-vr-code-visualizer/code_visualizer.html" # replace with your actual GitHub Pages link
|
49 |
components.iframe(aframe_url, height=500)
|
50 |
|
51 |
+
else:
|
52 |
+
st.info("Upload a Python file to begin visualizing and explaining it.")
|