masadonline commited on
Commit
cfe4dff
Β·
verified Β·
1 Parent(s): 4a33878

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import streamlit as st
2
  import ast
 
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,42 +12,41 @@ def load_model():
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.")
 
1
  import streamlit as st
2
  import ast
3
+ import base64
4
  import streamlit.components.v1 as components
5
  from transformers import pipeline
6
 
7
+ # --- Load summarizer model ---
8
  @st.cache_resource
9
  def load_model():
10
  summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum")
 
12
 
13
  summarizer = load_model()
14
 
 
15
  st.set_page_config(page_title="AR/VR Code Visualizer", layout="wide")
16
  st.title("πŸ‘“ AR/VR Enhanced Code Visualizer")
17
 
18
+ # --- Upload Python file ---
19
  uploaded_file = st.file_uploader("πŸ“ Upload your Python file", type=["py"])
20
 
21
+ # --- Parse code and show output ---
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("πŸ” Code Structure")
33
+ st.write(f"**Functions:** {functions or 'None'}")
34
+ st.write(f"**Classes:** {classes or 'None'}")
35
 
36
+ # Hugging Face Summarization
37
+ st.subheader("🧠 Code Explanation (AI)")
38
+ prompt = f"This code contains functions: {functions} and classes: {classes}. Explain what this code does."
39
  try:
40
  summary = summarizer(prompt, max_length=60, min_length=15, do_sample=False)
41
  st.success(summary[0]['summary_text'])
42
  except Exception as e:
43
  st.error(f"Summarization failed: {e}")
44
 
45
+ # Build dynamic A-Frame HTML
46
+ def generate_aframe_html(functions, classes):
47
+ elements = []
48
+ x_pos = -3
49
 
50
+ for fn in functions:
51
+ elements.append(f"""
52
+ <a-box