PatrickRedStar commited on
Commit
cdbc957
·
1 Parent(s): 652ea96
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import json
2
  import os
3
  import tempfile
4
- from dataclasses import asdict
5
  from typing import Any, Dict, List, Optional
6
 
7
  import gradio as gr
@@ -69,7 +68,7 @@ def analyze_logs(logs: str, source: str, use_retrieval: bool, use_nli: bool, ver
69
  )
70
 
71
 
72
- def ticket_template(state: Optional[Dict[str, Any]], logs: str) -> str:
73
  if not state:
74
  return "Run analysis first."
75
  try:
@@ -91,7 +90,7 @@ def ticket_template(state: Optional[Dict[str, Any]], logs: str) -> str:
91
  return template
92
 
93
 
94
- def export_json(state: Optional[Dict[str, Any]]):
95
  if not state:
96
  return None
97
  # If state is dict, dump; if already JSON string, use as-is.
@@ -105,7 +104,8 @@ def export_json(state: Optional[Dict[str, Any]]):
105
 
106
  with gr.Blocks(title="Log Compiler App") as demo:
107
  gr.Markdown("# Log Compiler App\nPaste logs/stacktrace to get incident classification, explanations, and runbook suggestions.")
108
- state = gr.State("")
 
109
 
110
  with gr.Row():
111
  with gr.Column(scale=1):
@@ -148,18 +148,18 @@ with gr.Blocks(title="Log Compiler App") as demo:
148
  analyze_btn.click(
149
  fn=analyze_logs,
150
  inputs=[logs_input, source_dropdown, use_retrieval, use_nli, verbosity_slider],
151
- outputs=[incident_md, explanation_md, cause_md, retrieval_df, verification_df, state, status],
152
  )
153
 
154
  ticket_btn.click(
155
  fn=ticket_template,
156
- inputs=[state, logs_input],
157
  outputs=ticket_md,
158
  )
159
 
160
  export_btn.click(
161
  fn=export_json,
162
- inputs=state,
163
  outputs=json_output,
164
  )
165
 
@@ -167,9 +167,4 @@ with gr.Blocks(title="Log Compiler App") as demo:
167
  if __name__ == "__main__":
168
  share_env = os.getenv("GRADIO_SHARE")
169
  in_hf_space = bool(os.getenv("SPACE_ID") or os.getenv("HF_SPACE"))
170
- # In HF Spaces share must be False; locally set GRADIO_SHARE=1 to force.
171
- if in_hf_space:
172
- share_flag = False
173
- else:
174
- share_flag = True if share_env is None else share_env.lower() in ("1", "true", "yes")
175
- demo.launch(server_name="0.0.0.0", share=share_flag)
 
1
  import json
2
  import os
3
  import tempfile
 
4
  from typing import Any, Dict, List, Optional
5
 
6
  import gradio as gr
 
68
  )
69
 
70
 
71
+ def ticket_template(state: Optional[str], logs: str) -> str:
72
  if not state:
73
  return "Run analysis first."
74
  try:
 
90
  return template
91
 
92
 
93
+ def export_json(state: Optional[str]):
94
  if not state:
95
  return None
96
  # If state is dict, dump; if already JSON string, use as-is.
 
104
 
105
  with gr.Blocks(title="Log Compiler App") as demo:
106
  gr.Markdown("# Log Compiler App\nPaste logs/stacktrace to get incident classification, explanations, and runbook suggestions.")
107
+ # Hidden textbox to store serialized state; avoids schema issues in HF Spaces.
108
+ state_box = gr.Textbox(visible=False, show_label=False)
109
 
110
  with gr.Row():
111
  with gr.Column(scale=1):
 
148
  analyze_btn.click(
149
  fn=analyze_logs,
150
  inputs=[logs_input, source_dropdown, use_retrieval, use_nli, verbosity_slider],
151
+ outputs=[incident_md, explanation_md, cause_md, retrieval_df, verification_df, state_box, status],
152
  )
153
 
154
  ticket_btn.click(
155
  fn=ticket_template,
156
+ inputs=[state_box, logs_input],
157
  outputs=ticket_md,
158
  )
159
 
160
  export_btn.click(
161
  fn=export_json,
162
+ inputs=state_box,
163
  outputs=json_output,
164
  )
165
 
 
167
  if __name__ == "__main__":
168
  share_env = os.getenv("GRADIO_SHARE")
169
  in_hf_space = bool(os.getenv("SPACE_ID") or os.getenv("HF_SPACE"))
170
+ demo.launch(server_name="0.0.0.0", share=True)