neuralworm commited on
Commit
4ef0b13
·
1 Parent(s): bf916e3

initial commit

Browse files
Files changed (1) hide show
  1. app.py +15 -0
app.py CHANGED
@@ -91,6 +91,13 @@ def generate_json_output(results, start_date, end_date):
91
  }
92
  return json.dumps(result, indent=4, ensure_ascii=False)
93
 
 
 
 
 
 
 
 
94
  # --- Main Gradio App ---
95
  with gr.Blocks() as app:
96
  with gr.Row():
@@ -99,6 +106,8 @@ with gr.Blocks() as app:
99
 
100
  calculate_btn = gr.Button("Calculate Gematria for Date Range")
101
  json_output = gr.Textbox(label="JSON Output")
 
 
102
 
103
  # --- Event Handlers ---
104
  def perform_calculation(start_date, end_date):
@@ -116,5 +125,11 @@ with gr.Blocks() as app:
116
  api_name="calculate_gematria"
117
  )
118
 
 
 
 
 
 
 
119
  if __name__ == "__main__":
120
  app.launch(share=False)
 
91
  }
92
  return json.dumps(result, indent=4, ensure_ascii=False)
93
 
94
+ def download_json(json_data, start_date, end_date):
95
+ """Downloads the JSON data to a file."""
96
+ filename = f"gematria_results_{start_date.strftime('%Y%m%d')}_{end_date.strftime('%Y%m%d')}.json"
97
+ with open(filename, 'w') as f:
98
+ f.write(json_data)
99
+ return gr.File.update(value=filename, visible=True)
100
+
101
  # --- Main Gradio App ---
102
  with gr.Blocks() as app:
103
  with gr.Row():
 
106
 
107
  calculate_btn = gr.Button("Calculate Gematria for Date Range")
108
  json_output = gr.Textbox(label="JSON Output")
109
+ download_btn = gr.Button("Download JSON")
110
+ json_file = gr.File(label="Downloaded JSON", visible=False)
111
 
112
  # --- Event Handlers ---
113
  def perform_calculation(start_date, end_date):
 
125
  api_name="calculate_gematria"
126
  )
127
 
128
+ download_btn.click(
129
+ download_json,
130
+ inputs=[json_output, start_date, end_date],
131
+ outputs=[json_file],
132
+ )
133
+
134
  if __name__ == "__main__":
135
  app.launch(share=False)