shukdevdatta123 commited on
Commit
1505346
·
verified ·
1 Parent(s): b9d3347

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -14
app.py CHANGED
@@ -26,18 +26,6 @@ def get_diagram_code(prompt, diagram_type, api_key):
26
  st.error(f"Error: {e}")
27
  return None
28
 
29
- # Function to convert SVG to PNG
30
- def convert_svg_to_png(svg_file):
31
- try:
32
- # Read the uploaded SVG file and convert it to PNG using cairosvg
33
- png_output = io.BytesIO()
34
- cairosvg.svg2png(file_obj=svg_file, write_to=png_output)
35
- png_output.seek(0)
36
- return png_output
37
- except Exception as e:
38
- st.error(f"Error during SVG to PNG conversion: {e}")
39
- return None
40
-
41
  # Adding custom CSS
42
  def custom_css():
43
  st.markdown("""
@@ -101,15 +89,58 @@ def custom_css():
101
  </style>
102
  """, unsafe_allow_html=True)
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  # Streamlit App UI
105
  def main():
106
  custom_css() # Apply custom CSS
 
107
 
108
  st.title("Generate Diagrams using AI and MermaidFlow")
109
 
110
  # Display a logo or icon with subtle animation
111
  image = Image.open("11.png") # Path to your image file
112
- st.image(image, width=300)
113
 
114
  # Display sample prompt
115
  with st.expander("Sample Prompt For Users", expanded=True):
@@ -145,7 +176,7 @@ def main():
145
  # Hide the spinner after diagram code is generated
146
  loading_spinner.empty()
147
 
148
- # Render Mermaid code to Streamlit
149
  st.code(diagram_code, language='mermaid')
150
 
151
  # Encode the Mermaid code for use in the MermaidFlow editor URL
 
26
  st.error(f"Error: {e}")
27
  return None
28
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Adding custom CSS
30
  def custom_css():
31
  st.markdown("""
 
89
  </style>
90
  """, unsafe_allow_html=True)
91
 
92
+ # Add anime.js CDN and custom JS for animations
93
+ def anime_js():
94
+ st.markdown("""
95
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/anime.min.js"></script>
96
+ <script>
97
+ document.addEventListener('DOMContentLoaded', function() {
98
+ // Example animation for the button when clicked
99
+ const button = document.querySelector('.stButton>button');
100
+ if (button) {
101
+ button.addEventListener('mouseover', function() {
102
+ anime({
103
+ targets: button,
104
+ scale: [1, 1.1],
105
+ duration: 300,
106
+ easing: 'easeInOutQuad'
107
+ });
108
+ });
109
+ button.addEventListener('mouseout', function() {
110
+ anime({
111
+ targets: button,
112
+ scale: [1.1, 1],
113
+ duration: 300,
114
+ easing: 'easeInOutQuad'
115
+ });
116
+ });
117
+ }
118
+
119
+ // Example animation for diagram generation code
120
+ const diagramCode = document.querySelector('pre code');
121
+ if (diagramCode) {
122
+ anime({
123
+ targets: diagramCode,
124
+ opacity: [0, 1],
125
+ translateY: [-50, 0],
126
+ duration: 1000,
127
+ easing: 'easeOutExpo'
128
+ });
129
+ }
130
+ });
131
+ </script>
132
+ """, unsafe_allow_html=True)
133
+
134
  # Streamlit App UI
135
  def main():
136
  custom_css() # Apply custom CSS
137
+ anime_js() # Add anime.js functionality
138
 
139
  st.title("Generate Diagrams using AI and MermaidFlow")
140
 
141
  # Display a logo or icon with subtle animation
142
  image = Image.open("11.png") # Path to your image file
143
+ st.image(image, width=300, use_column_width=False)
144
 
145
  # Display sample prompt
146
  with st.expander("Sample Prompt For Users", expanded=True):
 
176
  # Hide the spinner after diagram code is generated
177
  loading_spinner.empty()
178
 
179
+ # Render Mermaid code to Streamlit with animation
180
  st.code(diagram_code, language='mermaid')
181
 
182
  # Encode the Mermaid code for use in the MermaidFlow editor URL