baqarhussain commited on
Commit
d2f05a1
·
verified ·
1 Parent(s): ebf461d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -26
app.py CHANGED
@@ -1,10 +1,10 @@
1
- import gradio as gr
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(file):
27
- data = extract_name_status(file)
28
-
29
  if not data:
30
- return "No valid Name-Status data found in the file."
 
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
- # Save the plot to a buffer
47
- buffer = io.BytesIO()
48
- plt.savefig(buffer, format="png")
49
- buffer.seek(0)
50
- return buffer
51
 
52
- # Gradio interface
53
- def interface(file):
54
- return create_graph(file)
55
 
56
- # Launch the Gradio app
57
- inputs = gr.inputs.File(label="Upload Word File (.docx)")
58
- outputs = gr.outputs.Image(type="file", label="Graph: Name vs Status")
 
 
 
 
 
 
 
 
59
 
60
- gr.Interface(
61
- fn=interface,
62
- inputs=inputs,
63
- outputs=outputs,
64
- title="Name vs Status Graph",
65
- description="Upload a Word file containing 'Name: <Name>, Status: <Status>' data to generate a graph."
66
- ).launch()
 
 
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}")