File size: 1,793 Bytes
8c52bbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import ast
import streamlit.components.v1 as components
from transformers import pipeline

# --- App title ---
st.set_page_config(page_title="AR/VR Enhanced Code Learning", layout="wide")
st.title("πŸ‘“ AR/VR Enhanced Code Visualizer")

# --- File upload ---
uploaded_file = st.file_uploader("Upload your Python file", type=["py"])

# --- Hugging Face model ---
@st.cache_resource
def load_model():
    summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
    return summarizer

summarizer = load_model()

# --- Process file ---
if uploaded_file is not None:
    code = uploaded_file.read().decode('utf-8')
    st.subheader("πŸ“„ Uploaded Code")
    st.code(code, language='python')

    # --- Parse AST ---
    tree = ast.parse(code)
    functions = [node.name for node in ast.walk(tree) if isinstance(node, ast.FunctionDef)]
    classes = [node.name for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]

    st.subheader("πŸ› οΈ Detected Code Elements")
    st.write(f"**Functions:** {functions}")
    st.write(f"**Classes:** {classes}")

    # --- Hugging Face Summary ---
    st.subheader("🧠 AI Explanation of Code")
    input_text = f"This Python code contains functions: {functions} and classes: {classes}. Explain their purpose simply."
    summary = summarizer(input_text, max_length=60, min_length=10, do_sample=False)
    st.write(summary[0]['summary_text'])

    # --- AR/VR Viewer ---
    st.subheader("🌐 AR/VR Visualization (Demo)")

    st.info("This is a sample AR/VR scene visualizing functions/classes. Future versions will show dynamic graphs of your code!")

    aframe_url = "https://aframe.io/aframe/examples/showcase/helloworld/"  # Placeholder demo scene

    components.iframe(aframe_url, height=500)