Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
import
|
| 2 |
from docx import Document
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
-
import io
|
| 5 |
from collections import Counter
|
|
|
|
| 6 |
|
| 7 |
-
# Function to extract Name and Status from the Word file
|
| 8 |
def extract_name_status(file):
|
| 9 |
document = Document(file)
|
| 10 |
name_status_list = []
|
|
@@ -23,13 +23,11 @@ def extract_name_status(file):
|
|
| 23 |
return name_status_list
|
| 24 |
|
| 25 |
# Function to create a bar chart for Name vs Status
|
| 26 |
-
def create_graph(
|
| 27 |
-
data = extract_name_status(file)
|
| 28 |
-
|
| 29 |
if not data:
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
names = [item[0] for item in data]
|
| 33 |
statuses = [item[1] for item in data]
|
| 34 |
|
| 35 |
# Count statuses
|
|
@@ -43,24 +41,29 @@ def create_graph(file):
|
|
| 43 |
ax.set_title("Graph: Name vs Status", fontsize=16)
|
| 44 |
plt.tight_layout()
|
| 45 |
|
| 46 |
-
|
| 47 |
-
buffer = io.BytesIO()
|
| 48 |
-
plt.savefig(buffer, format="png")
|
| 49 |
-
buffer.seek(0)
|
| 50 |
-
return buffer
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
|
| 56 |
-
#
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
from docx import Document
|
| 3 |
import matplotlib.pyplot as plt
|
|
|
|
| 4 |
from collections import Counter
|
| 5 |
+
import io
|
| 6 |
|
| 7 |
+
# Function to extract Name and Status data from the Word file
|
| 8 |
def extract_name_status(file):
|
| 9 |
document = Document(file)
|
| 10 |
name_status_list = []
|
|
|
|
| 23 |
return name_status_list
|
| 24 |
|
| 25 |
# Function to create a bar chart for Name vs Status
|
| 26 |
+
def create_graph(data):
|
|
|
|
|
|
|
| 27 |
if not data:
|
| 28 |
+
st.error("No valid Name-Status data found in the file.")
|
| 29 |
+
return None
|
| 30 |
|
|
|
|
| 31 |
statuses = [item[1] for item in data]
|
| 32 |
|
| 33 |
# Count statuses
|
|
|
|
| 41 |
ax.set_title("Graph: Name vs Status", fontsize=16)
|
| 42 |
plt.tight_layout()
|
| 43 |
|
| 44 |
+
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# Streamlit app
|
| 47 |
+
st.title("Name vs Status Graph Application")
|
| 48 |
+
st.write("Upload a Word file (.docx) containing `Name` and `Status` data to generate a bar chart.")
|
| 49 |
|
| 50 |
+
# File upload section
|
| 51 |
+
uploaded_file = st.file_uploader("Upload a Word file (.docx)", type="docx")
|
| 52 |
+
if uploaded_file:
|
| 53 |
+
try:
|
| 54 |
+
# Extract Name and Status data
|
| 55 |
+
data = extract_name_status(uploaded_file)
|
| 56 |
+
|
| 57 |
+
# Display extracted data
|
| 58 |
+
if data:
|
| 59 |
+
st.write("Extracted Data:")
|
| 60 |
+
st.write(data)
|
| 61 |
|
| 62 |
+
# Create and display the graph
|
| 63 |
+
fig = create_graph(data)
|
| 64 |
+
if fig:
|
| 65 |
+
st.pyplot(fig)
|
| 66 |
+
else:
|
| 67 |
+
st.error("No valid data found in the uploaded file.")
|
| 68 |
+
except Exception as e:
|
| 69 |
+
st.error(f"An error occurred: {e}")
|