Hitheshrai commited on
Commit
680207c
·
verified ·
1 Parent(s): 3258bc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
2
  import matplotlib.pyplot as plt
3
  import numpy as np
4
  import matplotlib.animation as animation
 
 
5
 
6
  # Set up page configuration
7
  st.set_page_config(page_title="Hithesh Rai - Interactive Bohr Model of the Atom", page_icon="🔬")
@@ -53,11 +55,11 @@ def update(frame):
53
  electron.set_data([x], [y]) # Wrap x and y in lists to avoid RuntimeError
54
  return electrons
55
 
56
- # Animation
57
  ani = animation.FuncAnimation(fig, update, frames=range(200), interval=50, blit=True)
58
 
59
- # Display animation in Streamlit
60
- st.pyplot(fig)
61
-
62
- # Footer
63
- st.write("Explore the Bohr Model! Adjust the number of electrons and watch them orbit around the nucleus.")
 
2
  import matplotlib.pyplot as plt
3
  import numpy as np
4
  import matplotlib.animation as animation
5
+ from io import BytesIO
6
+ import base64
7
 
8
  # Set up page configuration
9
  st.set_page_config(page_title="Hithesh Rai - Interactive Bohr Model of the Atom", page_icon="🔬")
 
55
  electron.set_data([x], [y]) # Wrap x and y in lists to avoid RuntimeError
56
  return electrons
57
 
58
+ # Generate animation
59
  ani = animation.FuncAnimation(fig, update, frames=range(200), interval=50, blit=True)
60
 
61
+ # Save animation as HTML and embed in Streamlit
62
+ html_anim = BytesIO()
63
+ ani.save(html_anim, writer="html", fps=20)
64
+ html_data = base64.b64encode(html_anim.getvalue()).decode("utf-8")
65
+ st.components.v1.html(f"<div align='center'><img src='data:image/gif;base64,{html_data}'></div>", height=500)