Spaces:
Sleeping
Sleeping
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 --- | |
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) | |