ArkenB commited on
Commit
feb751a
·
verified ·
1 Parent(s): 97bc071

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import requests
5
+
6
+ # FastAPI endpoints
7
+ GET_API_URL = "http://127.0.0.1:8000/get_s_matrix/"
8
+ POST_API_URL = "http://127.0.0.1:8000/process_s_matrix/"
9
+
10
+ # Streamlit app setup
11
+ st.set_page_config(page_title="S-Matrix to RLC Converter", layout="wide")
12
+ st.title("S-Matrix to RLC Converter")
13
+ st.markdown("""
14
+ <style>
15
+ .stButton>button {
16
+ background-color: #4CAF50;
17
+ color: white;
18
+ border: none;
19
+ padding: 10px 20px;
20
+ font-size: 16px;
21
+ border-radius: 5px;
22
+ }
23
+ .stButton>button:hover {
24
+ background-color: #45a049;
25
+ }
26
+ </style>
27
+ """, unsafe_allow_html=True)
28
+
29
+ # Fetch S-matrix data
30
+ st.header("1. Fetch S-Matrix Data")
31
+ col1, col2 = st.columns(2)
32
+
33
+ with col1:
34
+ if st.button("Fetch as JSON"):
35
+ response = requests.get(GET_API_URL, params={"format": "json"})
36
+ if response.status_code == 200:
37
+ s_matrix = response.json()["s_matrix"]
38
+ st.success("Data fetched successfully!")
39
+ st.write(pd.DataFrame(s_matrix, columns=["S11", "S12"]))
40
+ else:
41
+ st.error("Failed to fetch data.")
42
+
43
+ with col2:
44
+ if st.button("Fetch as CSV"):
45
+ response = requests.get(GET_API_URL, params={"format": "csv"})
46
+ if response.status_code == 200:
47
+ st.success("CSV downloaded. Check your downloads folder!")
48
+ st.download_button("Download CSV", response.content, file_name="s_matrix.csv")
49
+ else:
50
+ st.error("Failed to fetch data.")
51
+
52
+ # Process S-matrix
53
+ if "s_matrix" in locals():
54
+ st.header("2. Process S-Matrix")
55
+ if st.button("Calculate RLC"):
56
+ payload = {"s_matrix": s_matrix}
57
+ response = requests.post(POST_API_URL, json=payload)
58
+
59
+ if response.status_code == 200:
60
+ rlc_values = response.json()["rlc_values"]
61
+ rlc_df = pd.DataFrame(rlc_values)
62
+ st.write("RLC Results✅")
63
+ st.dataframe(rlc_df)
64
+
65
+ # Copy-to-clipboard button
66
+ st.write("Copy Results")
67
+ st.code(rlc_df.to_csv(index=False), language="plaintext")
68
+ st.download_button("Copy to Clipboard", rlc_df.to_csv(index=False), file_name="rlc_results.csv")
69
+ else:
70
+ st.error("Failed to process data.")
71
+
72
+