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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -25
app.py CHANGED
@@ -3,14 +3,7 @@ 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")
@@ -18,33 +11,42 @@ def load_model():
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
 
 
 
 
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.")