Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 4.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
  1. import numpy as np
  2. import streamlit as st
  3. import streamlit.components.v1 as components
  4. from ThyroidProject.utils.common import read_html_file
  5. from pathlib import Path
  6. import pandas as pd
  7. import ydf
  8. import os
  9. # Load the saved model
  10. model = ydf.load_model('model')
  11. data_mapping = {"Male": "M", "Female": "F", True: "t", False: "f"}
  12. target = ['Negative', 'Hypothyroid', 'Hyperthyroid']
  13. # Streamlit App
  14. def main():
  15. st.title("Thyroid Disease Prediction App")
  16. st.image("templates/istockphoto-1316440125-612x612.jpg")
  17. # Button to trigger displaying or hiding HTML
  18. display_button_drift = st.button("Drift Report")
  19. display_button_test = st.button("Test Report")
  20. # File path of your HTML file
  21. html_file_path_drift = Path(os.path.join("drift_reports", "report.html"))
  22. html_file_path_test = Path(os.path.join("drift_reports", "test.html"))
  23. if display_button_drift:
  24. # Read HTML content
  25. html_content = read_html_file(html_file_path_drift)
  26. # Display HTML content
  27. components.html(html_content, width=1000, height=800, scrolling=True)
  28. if display_button_test:
  29. # Read HTML content
  30. html_content = read_html_file(html_file_path_test)
  31. # Display HTML content
  32. components.html(html_content, width=1000, height=800, scrolling=True)
  33. # Sidebar with user input
  34. st.sidebar.header("Input Parameters")
  35. # Collect user input
  36. age = st.sidebar.slider("Age", 1, 100, 25)
  37. sex = st.sidebar.selectbox("Sex", ["Male", "Female"])
  38. on_thyroxine = st.sidebar.checkbox("On Thyroxine")
  39. query_on_thyroxine = st.sidebar.checkbox("Query On Thyroxine")
  40. on_antihyroid_meds = st.sidebar.checkbox("on antihyroid meds")
  41. sick = st.sidebar.checkbox("Sick")
  42. pregnant = st.sidebar.checkbox("Pregnant")
  43. thyroid_surgery = st.sidebar.checkbox("Undergone Thyroid Surgery")
  44. I131_treatment = st.sidebar.checkbox("I131 treatment")
  45. query_hypothyroid = st.sidebar.checkbox("? Hypothyroid")
  46. query_hyperthyroid = st.sidebar.checkbox("? Hyperthyroid")
  47. lithium = st.sidebar.checkbox("Lithium")
  48. goitre = st.sidebar.checkbox("Goitre")
  49. tumor = st.sidebar.checkbox("Tumor")
  50. hypopituitary = st.sidebar.checkbox("Hypopituitary")
  51. psych = st.sidebar.checkbox("Psych")
  52. TSH = st.sidebar.number_input(
  53. label="TSH", value=None, placeholder="0.005<=TSH<=530.00")
  54. T3 = st.sidebar.number_input(
  55. label="T3", value=None, placeholder="0.05<=T3<=18.00")
  56. TT4 = st.sidebar.number_input(
  57. label="TT4", value=None, placeholder="2.00<=TT4<=600.00")
  58. T4U = st.sidebar.number_input(
  59. label="T4U", value=None, placeholder="0.170<=TT4<=2.33")
  60. FTI = st.sidebar.number_input(
  61. label="FTI", value=None, placeholder="1.4<=FTI<=881")
  62. submit = st.sidebar.button("Submit")
  63. if submit:
  64. cols = ['age', 'sex', 'on_thyroxine', 'query_on_thyroxine', 'on_antihyroid_meds', 'sick', 'pregnant',
  65. 'thyroid_surgery', 'I131_treatment', 'query_hypothyroid', 'query_hyperthyroid', 'lithium', 'goitre',
  66. 'tumor', 'hypopituitary', 'psych', 'TSH', 'T3', 'TT4', 'T4U', 'FTI']
  67. data = [age, data_mapping.get(sex), data_mapping.get(on_thyroxine), data_mapping.get(query_on_thyroxine),
  68. data_mapping.get(on_antihyroid_meds), data_mapping.get(
  69. sick), data_mapping.get(pregnant),
  70. data_mapping.get(thyroid_surgery), data_mapping.get(
  71. I131_treatment),
  72. data_mapping.get(query_hypothyroid), data_mapping.get(
  73. query_hyperthyroid), data_mapping.get(lithium),
  74. data_mapping.get(goitre), data_mapping.get(
  75. tumor), data_mapping.get(hypopituitary),
  76. data_mapping.get(psych), TSH, T3, TT4, T4U, FTI]
  77. df = pd.DataFrame(np.array(data).reshape(1, len(data)), columns=cols)
  78. preds = model.predict(df)
  79. result = int(np.argmax(preds, axis=1))
  80. st.subheader("Prediction:")
  81. st.write(
  82. f"The predicted thyroid disease class is: {target[result].upper()}")
  83. if __name__ == "__main__":
  84. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...