Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 57 |
ani = animation.FuncAnimation(fig, update, frames=range(200), interval=50, blit=True)
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
st.
|
|
|
|
| 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)
|