stevafernandes commited on
Commit
be94342
·
verified ·
1 Parent(s): 37f3320

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -12
app.py CHANGED
@@ -40,25 +40,66 @@ def reset_latch():
40
  return "0", "1", "HOLD", ""
41
 
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  with gr.Blocks(title="SR Latch Simulator") as demo:
44
- gr.Markdown("## SR Latch Simulator")
45
  gr.Markdown(
46
- "Toggle **S** (set) and **R** (reset) inputs to see how the latch responds. "
47
- "The latch remembers its previous state when both inputs are 0."
48
  )
49
 
50
  with gr.Row():
51
  s_input = gr.Radio(choices=["0", "1"], value="0", label="S (Set)")
52
  r_input = gr.Radio(choices=["0", "1"], value="0", label="R (Reset)")
53
 
54
- apply_btn = gr.Button("Apply", variant="primary")
 
 
55
 
56
  with gr.Row():
57
- q_output = gr.Textbox(label="Q", value="0", interactive=False)
58
- q_bar_output = gr.Textbox(label="Q'", value="1", interactive=False)
59
- state_output = gr.Textbox(label="State", value="HOLD", interactive=False)
60
 
61
- gr.Markdown("### Truth table")
62
  gr.Dataframe(
63
  value=[
64
  ["0", "0", "Prev", "Prev", "Hold"],
@@ -68,12 +109,16 @@ with gr.Blocks(title="SR Latch Simulator") as demo:
68
  ],
69
  headers=["S", "R", "Q", "Q'", "State"],
70
  interactive=False,
 
71
  )
72
 
73
  gr.Markdown("### History")
74
- history_box = gr.Textbox(label="Log", lines=8, interactive=False)
75
-
76
- reset_btn = gr.Button("Reset latch")
 
 
 
77
 
78
  apply_btn.click(
79
  fn=sr_latch,
@@ -88,4 +133,4 @@ with gr.Blocks(title="SR Latch Simulator") as demo:
88
  )
89
 
90
  if __name__ == "__main__":
91
- demo.launch()
 
40
  return "0", "1", "HOLD", ""
41
 
42
 
43
+ custom_css = """
44
+ .gradio-container {
45
+ max-width: 720px !important;
46
+ margin: auto;
47
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
48
+ }
49
+ h1 {
50
+ color: #1a1a2e !important;
51
+ font-size: 28px !important;
52
+ font-weight: 700 !important;
53
+ margin-bottom: 4px !important;
54
+ }
55
+ .subtitle {
56
+ color: #5a5a6e !important;
57
+ font-size: 15px !important;
58
+ }
59
+ .output-box textarea {
60
+ font-size: 22px !important;
61
+ font-weight: 600 !important;
62
+ text-align: center !important;
63
+ color: #1a1a2e !important;
64
+ }
65
+ .history-box textarea {
66
+ font-family: "SF Mono", "Fira Code", "Consolas", monospace !important;
67
+ font-size: 13px !important;
68
+ color: #3a3a4e !important;
69
+ }
70
+ .truth-table-wrap table {
71
+ font-size: 14px !important;
72
+ }
73
+ .truth-table-wrap th {
74
+ color: #5a5a6e !important;
75
+ font-weight: 600 !important;
76
+ }
77
+ .truth-table-wrap td {
78
+ color: #1a1a2e !important;
79
+ }
80
+ """
81
+
82
  with gr.Blocks(title="SR Latch Simulator") as demo:
83
+ gr.Markdown("# SR Latch Simulator")
84
  gr.Markdown(
85
+ "Toggle the S (set) and R (reset) inputs and click Apply to observe the latch behavior.",
86
+ elem_classes=["subtitle"],
87
  )
88
 
89
  with gr.Row():
90
  s_input = gr.Radio(choices=["0", "1"], value="0", label="S (Set)")
91
  r_input = gr.Radio(choices=["0", "1"], value="0", label="R (Reset)")
92
 
93
+ with gr.Row():
94
+ apply_btn = gr.Button("Apply", variant="primary")
95
+ reset_btn = gr.Button("Reset")
96
 
97
  with gr.Row():
98
+ q_output = gr.Textbox(label="Q", value="0", interactive=False, elem_classes=["output-box"])
99
+ q_bar_output = gr.Textbox(label="Q'", value="1", interactive=False, elem_classes=["output-box"])
100
+ state_output = gr.Textbox(label="State", value="HOLD", interactive=False, elem_classes=["output-box"])
101
 
102
+ gr.Markdown("### Truth Table")
103
  gr.Dataframe(
104
  value=[
105
  ["0", "0", "Prev", "Prev", "Hold"],
 
109
  ],
110
  headers=["S", "R", "Q", "Q'", "State"],
111
  interactive=False,
112
+ elem_classes=["truth-table-wrap"],
113
  )
114
 
115
  gr.Markdown("### History")
116
+ history_box = gr.Textbox(
117
+ label="Log",
118
+ lines=6,
119
+ interactive=False,
120
+ elem_classes=["history-box"],
121
+ )
122
 
123
  apply_btn.click(
124
  fn=sr_latch,
 
133
  )
134
 
135
  if __name__ == "__main__":
136
+ demo.launch(css=custom_css, theme=gr.themes.Base())