Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import ast
|
3 |
+
import streamlit.components.v1 as components
|
4 |
+
from transformers import pipeline
|
5 |
+
|
6 |
+
# --- App title ---
|
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")
|
17 |
+
return summarizer
|
18 |
+
|
19 |
+
summarizer = load_model()
|
20 |
+
|
21 |
+
# --- Process file ---
|
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 |
+
# --- Parse AST ---
|
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("π οΈ Detected Code Elements")
|
33 |
+
st.write(f"**Functions:** {functions}")
|
34 |
+
st.write(f"**Classes:** {classes}")
|
35 |
+
|
36 |
+
# --- Hugging Face Summary ---
|
37 |
+
st.subheader("π§ AI Explanation of Code")
|
38 |
+
input_text = f"This Python code contains functions: {functions} and classes: {classes}. Explain their purpose simply."
|
39 |
+
summary = summarizer(input_text, max_length=60, min_length=10, do_sample=False)
|
40 |
+
st.write(summary[0]['summary_text'])
|
41 |
+
|
42 |
+
# --- AR/VR Viewer ---
|
43 |
+
st.subheader("π AR/VR Visualization (Demo)")
|
44 |
+
|
45 |
+
st.info("This is a sample AR/VR scene visualizing functions/classes. Future versions will show dynamic graphs of your code!")
|
46 |
+
|
47 |
+
aframe_url = "https://aframe.io/aframe/examples/showcase/helloworld/" # Placeholder demo scene
|
48 |
+
|
49 |
+
components.iframe(aframe_url, height=500)
|
50 |
+
|