simran19 commited on
Commit
d21276c
·
verified ·
1 Parent(s): af613b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import joblib
2
  from sklearn.preprocessing import StandardScaler
3
- from flask import Flask,render_template,request
4
  import numpy as np
5
  import requests
6
 
@@ -11,19 +11,26 @@ model=joblib.load('crypto.pkl')
11
  scaler_x=joblib.load('scaler_x.pkl')
12
 
13
  @app.route('/')
14
- def home():
15
- try:
16
- response = requests.get('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd', timeout=5) #fetched using API
17
- response.raise_for_status() # This will raise an HTTPError if status != 200
18
- data = response.json()
19
- btc_price = data['bitcoin']['usd']
20
- except Exception as e:
21
- print("Error fetching price:", e) # This prints error to console
22
- btc_price = "Error fetching price"
23
-
24
- return render_template('home.html', btc_price=btc_price)
 
 
 
 
25
 
26
 
 
 
 
27
 
28
  @app.route('/start')
29
  def startt():
 
1
  import joblib
2
  from sklearn.preprocessing import StandardScaler
3
+ from flask import Flask,render_template,request, redirect, url_for
4
  import numpy as np
5
  import requests
6
 
 
11
  scaler_x=joblib.load('scaler_x.pkl')
12
 
13
  @app.route('/')
14
+ def home():
15
+ print("HOME ROUTE ACCESSED!") # Debug print
16
+ try:
17
+ response = requests.get('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd', timeout=5)
18
+ response.raise_for_status()
19
+ data = response.json()
20
+ btc_price = data['bitcoin']['usd']
21
+ print(f"BTC Price: {btc_price}") # Debug print
22
+ except Exception as e:
23
+ print("Error fetching price:", e)
24
+ btc_price = "Error fetching price"
25
+
26
+ print("Rendering home.html") # Debug print
27
+ return render_template('home.html', btc_price=btc_price)
28
+
29
 
30
 
31
+ @app.route('/home')
32
+ def startt():
33
+ return redirect(url_for('home')) # Redirect to the 'home' function
34
 
35
  @app.route('/start')
36
  def startt():