HMZaheer commited on
Commit
1d2ebdf
·
verified ·
1 Parent(s): 6325912

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -80
app.py CHANGED
@@ -1,82 +1,50 @@
1
  import streamlit as st
2
- import matplotlib.pyplot as plt
3
- import pandas as pd
4
- import numpy as np
5
  from PIL import Image
6
-
7
- # Utility functions
8
- def analyze_curve(temp, weight):
9
- temp = np.array(temp)
10
- weight = np.array(weight)
11
-
12
- if len(temp) < 5:
13
- return None, None, None
14
-
15
- # Normalize if >100
16
- if weight.max() > 100:
17
- weight = 100 * weight / weight[0]
18
-
19
- # Derivative
20
- dy = np.gradient(weight, temp)
21
-
22
- # Onset
23
- onset_idx = np.argmax(dy < -0.05)
24
- onset_temp = temp[onset_idx] if onset_idx > 0 else None
25
-
26
- # Peak degradation
27
- peak_idx = np.argmin(dy)
28
- peak_temp = temp[peak_idx] if peak_idx > 0 else None
29
-
30
- # Weight loss
31
- weight_loss = weight[0] - weight[-1]
32
-
33
- return onset_temp, peak_temp, weight_loss
34
-
35
-
36
- st.title("TGA Graph Interpreter (Multi-Curve Support)")
37
-
38
- st.write("""
39
- Upload your TGA data in **CSV/Excel** format with columns:
40
- - First column = Temperature (°C)
41
- - Other columns = Weight (%) for each thermogram
42
- """)
43
-
44
- uploaded_file = st.file_uploader("Upload CSV or Excel", type=["csv", "xlsx"])
45
-
46
- if uploaded_file:
47
- # Read data
48
- if uploaded_file.name.endswith(".csv"):
49
- df = pd.read_csv(uploaded_file)
50
- else:
51
- df = pd.read_excel(uploaded_file)
52
-
53
- st.write("### Uploaded Data", df.head())
54
-
55
- temp = df.iloc[:, 0]
56
- fig, ax = plt.subplots()
57
-
58
- for col in df.columns[1:]:
59
- weight = df[col]
60
- onset, peak, loss = analyze_curve(temp, weight)
61
-
62
- ax.plot(temp, weight, label=col)
63
-
64
- st.subheader(f"Results for {col}")
65
- if onset:
66
- st.write(f"- **Onset Temperature:** {onset:.2f} °C")
67
- if peak:
68
- st.write(f"- **Peak Degradation Temperature:** {peak:.2f} °C")
69
- st.write(f"- **Weight Loss:** {loss:.2f} %")
70
-
71
- ax.set_xlabel("Temperature (°C)")
72
- ax.set_ylabel("Weight (%)")
73
- ax.legend()
74
- st.pyplot(fig)
75
-
76
- st.write("---")
77
- st.write("Alternatively, upload a TGA **image (PNG/JPG)** just for visualization (no extraction).")
78
-
79
- img_file = st.file_uploader("Upload TGA Image", type=["png", "jpg", "jpeg"])
80
- if img_file:
81
- img = Image.open(img_file)
82
- st.image(img, caption="Uploaded TGA Graph", use_column_width=True)
 
1
  import streamlit as st
 
 
 
2
  from PIL import Image
3
+ import io
4
+
5
+ st.set_page_config(page_title="TGA Graph Interpreter", layout="wide")
6
+
7
+ st.title("TGA Graph Interpreter")
8
+ st.write("Upload TGA thermograms and record degradation details. The app will generate a structured discussion.")
9
+
10
+ uploaded_files = st.file_uploader(
11
+ "Upload thermogram(s)",
12
+ type=["png", "jpg", "jpeg", "pdf"],
13
+ accept_multiple_files=True
14
+ )
15
+
16
+ all_discussions = []
17
+
18
+ if uploaded_files:
19
+ for i, uploaded_file in enumerate(uploaded_files):
20
+ st.subheader(f"Thermogram {i+1}: {uploaded_file.name}")
21
+
22
+ # Display thermogram
23
+ file_bytes = uploaded_file.read()
24
+ image = Image.open(io.BytesIO(file_bytes))
25
+ st.image(image, use_container_width=True)
26
+
27
+ st.markdown("**Enter analysis details:**")
28
+ onset_temp = st.number_input(f"Onset temperature (°C) for {uploaded_file.name}", min_value=0, step=1)
29
+ peak_temp = st.number_input(f"Peak degradation temperature (°C) for {uploaded_file.name}", min_value=0, step=1)
30
+ weight_loss = st.number_input(f"Total weight loss (%) for {uploaded_file.name}", min_value=0.0, step=0.1)
31
+ residue = st.number_input(f"Residue at 800 °C (%) for {uploaded_file.name}", min_value=0.0, step=0.1)
32
+
33
+ if st.button(f"Add Discussion for {uploaded_file.name}"):
34
+ discussion = (
35
+ f"**{uploaded_file.name}**:\n"
36
+ f"- Onset of degradation observed at ~{onset_temp} °C.\n"
37
+ f"- Major degradation peak at ~{peak_temp} °C.\n"
38
+ f"- The material shows a total weight loss of ~{weight_loss:.2f}%.\n"
39
+ f"- Residual mass at 800 °C is ~{residue:.2f}%.\n\n"
40
+ f"These results indicate thermal stability until {onset_temp} °C, "
41
+ f"with significant decomposition occurring around {peak_temp} °C. "
42
+ f"The remaining char (~{residue:.2f}%) suggests potential "
43
+ f"applications where high-temperature stability is desired."
44
+ )
45
+ all_discussions.append(discussion)
46
+
47
+ if all_discussions:
48
+ st.header("Discussion")
49
+ for d in all_discussions:
50
+ st.markdown(d)