Darshan03 commited on
Commit
477e265
·
verified ·
1 Parent(s): 7bc917b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -44,7 +44,6 @@ def scrape_website(url):
44
  return f"Failed to retrieve page. Status code: {response.status_code}"
45
 
46
 
47
-
48
  # Load environment variables from .env
49
  load_dotenv()
50
 
@@ -80,6 +79,12 @@ if uploaded_file is not None:
80
  "Real Estate",
81
  "Utilities"
82
  ]
 
 
 
 
 
 
83
  def configure_generative_ai():
84
  """Configures the generative AI model and starts a chat session."""
85
  genai.configure(api_key=Config.GOOGLE_API_KEY)
@@ -150,7 +155,6 @@ if uploaded_file is not None:
150
  scenario_response = get_response(chat_session, scenario_prompt)
151
  json_output = extract_json_content(scenario_response.text)
152
  scenario_data = json.loads(json_output)
153
- os.makedirs(os.path.dirname(Config.SCENARIO_OUTPUT_FILE), exist_ok=True)
154
  with open(Config.SCENARIO_OUTPUT_FILE, "w") as f:
155
  json.dump(scenario_data, f, indent=4)
156
  st.success("Market scenarios saved successfully!")
@@ -163,6 +167,7 @@ if uploaded_file is not None:
163
 
164
  # Save simulation results
165
  simulation_results_file = "output_files/simulation_results.json"
 
166
  with open(simulation_results_file, "w") as file:
167
  json.dump(simulation_results, file, indent=4)
168
  st.success("Monte Carlo Simulation completed!")
@@ -171,4 +176,4 @@ if uploaded_file is not None:
171
  st.write("Download Output Files")
172
  for file in [Config.OUTPUT_FILE, Config.SCENARIO_OUTPUT_FILE, simulation_results_file]:
173
  with open(file, "rb") as f:
174
- st.download_button(label=f"Download {file.split('/')[-1]}", data=f, file_name=file.split('/')[-1])
 
44
  return f"Failed to retrieve page. Status code: {response.status_code}"
45
 
46
 
 
47
  # Load environment variables from .env
48
  load_dotenv()
49
 
 
79
  "Real Estate",
80
  "Utilities"
81
  ]
82
+
83
+ # Create directories if they don't exist
84
+ os.makedirs(Config.STOCK_DATA_DIR, exist_ok=True)
85
+ os.makedirs(os.path.dirname(Config.OUTPUT_FILE), exist_ok=True)
86
+ os.makedirs(os.path.dirname(Config.SCENARIO_OUTPUT_FILE), exist_ok=True)
87
+
88
  def configure_generative_ai():
89
  """Configures the generative AI model and starts a chat session."""
90
  genai.configure(api_key=Config.GOOGLE_API_KEY)
 
155
  scenario_response = get_response(chat_session, scenario_prompt)
156
  json_output = extract_json_content(scenario_response.text)
157
  scenario_data = json.loads(json_output)
 
158
  with open(Config.SCENARIO_OUTPUT_FILE, "w") as f:
159
  json.dump(scenario_data, f, indent=4)
160
  st.success("Market scenarios saved successfully!")
 
167
 
168
  # Save simulation results
169
  simulation_results_file = "output_files/simulation_results.json"
170
+ os.makedirs(os.path.dirname(simulation_results_file), exist_ok=True)
171
  with open(simulation_results_file, "w") as file:
172
  json.dump(simulation_results, file, indent=4)
173
  st.success("Monte Carlo Simulation completed!")
 
176
  st.write("Download Output Files")
177
  for file in [Config.OUTPUT_FILE, Config.SCENARIO_OUTPUT_FILE, simulation_results_file]:
178
  with open(file, "rb") as f:
179
+ st.download_button(label=f"Download {file.split('/')[-1]}", data=f, file_name=file.split('/')[-1])