Update app.py
Browse files
app.py
CHANGED
|
@@ -1,92 +1,64 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
import pandas as pd
|
| 11 |
-
import os
|
| 12 |
-
import tempfile
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
# Convert the table to a Pandas DataFrame
|
| 61 |
-
df = table.df
|
| 62 |
-
|
| 63 |
-
# Display the extracted table
|
| 64 |
-
st.dataframe(df)
|
| 65 |
-
|
| 66 |
-
# Download buttons
|
| 67 |
-
col1, col2 = st.columns(2)
|
| 68 |
-
with col1:
|
| 69 |
-
csv = df.to_csv(index=False).encode('utf-8')
|
| 70 |
-
st.download_button(
|
| 71 |
-
label=f"Download as CSV",
|
| 72 |
-
data=csv,
|
| 73 |
-
file_name=f"table_{i+1}_page_{table.parsing_report['page']}.csv",
|
| 74 |
-
mime="text/csv"
|
| 75 |
-
)
|
| 76 |
-
with col2:
|
| 77 |
-
excel_file = df.to_excel(index=False, engine="xlsxwriter")
|
| 78 |
-
st.download_button(
|
| 79 |
-
label=f"Download as Excel",
|
| 80 |
-
data=excel_file,
|
| 81 |
-
file_name=f"table_{i+1}_page_{table.parsing_report['page']}.xlsx",
|
| 82 |
-
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 83 |
-
)
|
| 84 |
-
else:
|
| 85 |
-
st.write("No tables found in the selected pages.")
|
| 86 |
-
|
| 87 |
-
finally:
|
| 88 |
-
# Clean up the temporary file
|
| 89 |
-
os.unlink(temp_file_path)
|
| 90 |
-
|
| 91 |
-
except Exception as e:
|
| 92 |
-
st.error(f"An error occurred: {str(e)}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
+
def draw_circle(ax, center, radius, color='black', fill=False, lw=1.5):
|
| 6 |
+
circle = plt.Circle(center, radius, clip_on=False, edgecolor=color, facecolor='none' if not fill else color, lw=lw, fill=fill)
|
| 7 |
+
ax.add_artist(circle)
|
| 8 |
|
| 9 |
+
def draw_line(ax, start, end, color='black', lw=1.5):
|
| 10 |
+
ax.plot([start[0], end[0]], [start[1], end[1]], color=color, lw=lw)
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
def setup_plot(xlim=(-1.5, 1.5), ylim=(-1.5, 1.5), aspect='equal'):
|
| 13 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
| 14 |
+
ax.set_xlim(xlim)
|
| 15 |
+
ax.set_ylim(ylim)
|
| 16 |
+
ax.set_aspect(aspect)
|
| 17 |
+
ax.axis('off')
|
| 18 |
+
return fig, ax
|
| 19 |
|
| 20 |
+
def draw_shree_yantra(ax, radius=1, sides=12, line_skips=[2,5,7,10], circle_fill=False, line_color='black', circle_color='black'):
|
| 21 |
+
# Step 1: Draw outer circle
|
| 22 |
+
draw_circle(ax, (0, 0), radius, color=circle_color, fill=circle_fill, lw=2)
|
| 23 |
|
| 24 |
+
# Step 2: Draw polygon (e.g., dodecagon for 12 sides)
|
| 25 |
+
points = [np.array([np.cos(theta), np.sin(theta)]) for theta in np.linspace(0, 2*np.pi, sides, endpoint=False)]
|
| 26 |
+
polygon = plt.Polygon(points, closed=True, fill=False, edgecolor=circle_color, lw=2)
|
| 27 |
+
ax.add_artist(polygon)
|
| 28 |
|
| 29 |
+
# Step 3: Draw connecting lines based on skips
|
| 30 |
+
for i, p1 in enumerate(points):
|
| 31 |
+
for j, p2 in enumerate(points):
|
| 32 |
+
if i != j and abs(i - j) in line_skips:
|
| 33 |
+
draw_line(ax, p1 * radius, p2 * radius, color=line_color, lw=1.5)
|
| 34 |
+
|
| 35 |
+
# Additional steps can be implemented here following the traditional Shree Yantra construction
|
| 36 |
+
# For simplicity, this example draws a basic pattern
|
| 37 |
+
|
| 38 |
+
def main():
|
| 39 |
+
st.title("Shree Yantra Diagram Generator")
|
| 40 |
+
|
| 41 |
+
st.sidebar.header("Customize Your Shree Yantra")
|
| 42 |
+
|
| 43 |
+
# Sidebar controls
|
| 44 |
+
radius = st.sidebar.slider("Outer Circle Radius", 0.5, 2.0, 1.0, 0.1)
|
| 45 |
+
sides = st.sidebar.slider("Number of Sides (Polygon)", 6, 20, 12, 1)
|
| 46 |
+
line_skips = st.sidebar.multiselect("Line Skips", options=list(range(1, sides//2 +1)), default=[2,5,7,10])
|
| 47 |
+
line_color = st.sidebar.color_picker("Line Color", "#000000")
|
| 48 |
+
circle_color = st.sidebar.color_picker("Circle & Polygon Color", "#000000")
|
| 49 |
+
circle_fill = st.sidebar.checkbox("Fill Outer Circle", value=False)
|
| 50 |
+
|
| 51 |
+
st.write("### Shree Yantra Diagram")
|
| 52 |
+
|
| 53 |
+
fig, ax = setup_plot()
|
| 54 |
+
|
| 55 |
+
if not line_skips:
|
| 56 |
+
st.warning("Please select at least one line skip to draw connecting lines.")
|
| 57 |
+
else:
|
| 58 |
+
draw_shree_yantra(ax, radius=radius, sides=sides, line_skips=line_skips,
|
| 59 |
+
circle_fill=circle_fill, line_color=line_color, circle_color=circle_color)
|
| 60 |
+
|
| 61 |
+
st.pyplot(fig)
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|