baqarhussain commited on
Commit
d48422d
·
verified ·
1 Parent(s): af524a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -43
app.py CHANGED
@@ -1,13 +1,11 @@
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 = []
11
 
12
  for paragraph in document.paragraphs:
13
  if "Name:" in paragraph.text and "Status:" in paragraph.text:
@@ -18,52 +16,29 @@ def extract_name_status(file):
18
  if name_part and status_part:
19
  name = name_part.split(":")[1].strip()
20
  status = status_part.split(":")[1].strip()
21
- name_status_list.append((name, status))
22
 
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
34
- status_counts = Counter(statuses)
35
-
36
- # Plotting the graph
37
- fig, ax = plt.subplots(figsize=(8, 6))
38
- ax.bar(status_counts.keys(), status_counts.values(), color="skyblue")
39
- ax.set_xlabel("Status", fontsize=14)
40
- ax.set_ylabel("Count", fontsize=14)
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}")
 
1
  import streamlit as st
2
  from docx import Document
3
+ import pandas as pd
 
 
4
 
5
+ # Function to parse the Word file
6
+ def parse_word_file(file):
7
  document = Document(file)
8
+ data = []
9
 
10
  for paragraph in document.paragraphs:
11
  if "Name:" in paragraph.text and "Status:" in paragraph.text:
 
16
  if name_part and status_part:
17
  name = name_part.split(":")[1].strip()
18
  status = status_part.split(":")[1].strip()
19
+ data.append({"Name": name, "Status": status})
20
 
21
+ return data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  # Streamlit app
24
+ st.title("Display File Data in Separate Columns")
25
+ st.write("Upload a Word file containing `Name` and `Status` data to display it in separate columns.")
26
 
27
+ # File uploader
28
  uploaded_file = st.file_uploader("Upload a Word file (.docx)", type="docx")
29
  if uploaded_file:
30
  try:
31
+ # Parse the file
32
+ data = parse_word_file(uploaded_file)
33
+
 
34
  if data:
35
+ # Convert to DataFrame for display
36
+ df = pd.DataFrame(data)
37
 
38
+ # Display the data in separate columns
39
+ st.write("### Uploaded Data")
40
+ st.dataframe(df)
 
41
  else:
42
+ st.error("No valid Name-Status data found in the file.")
43
  except Exception as e:
44
  st.error(f"An error occurred: {e}")