Olivier-Truong commited on
Commit
0d54098
·
verified ·
1 Parent(s): 8d8d0d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -1,9 +1,18 @@
1
  # -*- coding: utf-8 -*-
2
 
3
  import torch
4
- import math
 
5
 
6
 
 
 
 
 
 
 
 
 
7
  dtype = torch.float
8
  device = torch.device("cpu")
9
  # device = torch.device("cuda:0") # Uncomment this to run on GPU
@@ -17,7 +26,7 @@ a = torch.randn((), device=device, dtype=dtype)
17
  b = torch.randn((), device=device, dtype=dtype)
18
  c = torch.randn((), device=device, dtype=dtype)
19
  d = torch.randn((), device=device, dtype=dtype)
20
- print(a, b, c, d)
21
  learning_rate = 1e-6
22
  for t in range(2000):
23
  # Forward pass: compute predicted y
@@ -26,7 +35,7 @@ for t in range(2000):
26
  # Compute and print loss
27
  loss = (y_pred - y).pow(2).sum().item()
28
  if t % 100 == 99:
29
- print(t, loss)
30
 
31
  # Backprop to compute gradients of a, b, c, d with respect to loss
32
  grad_y_pred = 2.0 * (y_pred - y)
@@ -42,4 +51,10 @@ for t in range(2000):
42
  d -= learning_rate * grad_d
43
 
44
 
45
- print(f'Result: y = {a.item()} + {b.item()} x + {c.item()} x^2 + {d.item()} x^3')
 
 
 
 
 
 
 
1
  # -*- coding: utf-8 -*-
2
 
3
  import torch
4
+ import math, sys
5
+ from flask import *
6
 
7
 
8
+ app = Flask(__name__)
9
+ app.config['data'] = ""
10
+
11
+ def print(data):
12
+ app.config['data'] += data + "<br>"
13
+ sys.stdout.write(data + "\n")
14
+ sys.stdout.flush()
15
+
16
  dtype = torch.float
17
  device = torch.device("cpu")
18
  # device = torch.device("cuda:0") # Uncomment this to run on GPU
 
26
  b = torch.randn((), device=device, dtype=dtype)
27
  c = torch.randn((), device=device, dtype=dtype)
28
  d = torch.randn((), device=device, dtype=dtype)
29
+ print(f"{a} {b} {c} {d}")
30
  learning_rate = 1e-6
31
  for t in range(2000):
32
  # Forward pass: compute predicted y
 
35
  # Compute and print loss
36
  loss = (y_pred - y).pow(2).sum().item()
37
  if t % 100 == 99:
38
+ print(str(t) + " " + str(loss))
39
 
40
  # Backprop to compute gradients of a, b, c, d with respect to loss
41
  grad_y_pred = 2.0 * (y_pred - y)
 
51
  d -= learning_rate * grad_d
52
 
53
 
54
+ print(f'Result: y = {a.item()} + {b.item()} x + {c.item()} x^2 + {d.item()} x^3')
55
+
56
+ @app.route('/')
57
+ def index():
58
+ return app.config["data"]
59
+
60
+ app.run(host= "0.0.0.0", port=7860)