Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,66 @@
|
|
| 1 |
-
|
| 2 |
-
import streamlit as st
|
| 3 |
from docx import Document
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import io
|
|
|
|
| 6 |
|
| 7 |
-
# Function to
|
| 8 |
-
def
|
| 9 |
document = Document(file)
|
| 10 |
-
|
|
|
|
| 11 |
for paragraph in document.paragraphs:
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
plt.tight_layout()
|
| 32 |
|
| 33 |
-
# Save plot to a
|
| 34 |
buffer = io.BytesIO()
|
| 35 |
plt.savefig(buffer, format="png")
|
| 36 |
buffer.seek(0)
|
| 37 |
return buffer
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
# File upload section
|
| 44 |
-
uploaded_file = st.file_uploader("Upload a Word file (.docx)", type="docx")
|
| 45 |
-
if uploaded_file:
|
| 46 |
-
# Step 1: Extract text data
|
| 47 |
-
data = extract_data_from_word(uploaded_file)
|
| 48 |
-
st.write("Extracted Text:")
|
| 49 |
-
st.text_area("Data Preview", value=data, height=200)
|
| 50 |
-
|
| 51 |
-
# Step 2: Calculate performance metric
|
| 52 |
-
performance = calculate_performance(data)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
st.image(meter_image, caption="Performance Meter")
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = []
|
| 11 |
+
|
| 12 |
for paragraph in document.paragraphs:
|
| 13 |
+
if "Name:" in paragraph.text and "Status:" in paragraph.text:
|
| 14 |
+
parts = paragraph.text.split(",")
|
| 15 |
+
name_part = next((part for part in parts if "Name:" in part), None)
|
| 16 |
+
status_part = next((part for part in parts if "Status:" in part), None)
|
| 17 |
+
|
| 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(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
|
| 36 |
+
status_counts = Counter(statuses)
|
| 37 |
+
|
| 38 |
+
# Plotting the graph
|
| 39 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
| 40 |
+
ax.bar(status_counts.keys(), status_counts.values(), color="skyblue")
|
| 41 |
+
ax.set_xlabel("Status", fontsize=14)
|
| 42 |
+
ax.set_ylabel("Count", fontsize=14)
|
| 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()
|