hwberry2 commited on
Commit
1b8bf98
·
1 Parent(s): f3edddc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -51
app.py CHANGED
@@ -1,54 +1,70 @@
1
  import gradio as gr
2
  import tensorflow as tf
3
 
4
- print("TensorFlow version:", tf.__version__)
5
-
6
- mnist = tf.keras.datasets.mnist
7
-
8
- (x_train, y_train), (x_test, y_test) = mnist.load_data()
9
- x_train, x_test = x_train / 255.0, x_test / 255.0
10
-
11
- model = tf.keras.models.Sequential([
12
- tf.keras.layers.Flatten(input_shape=(28, 28)),
13
- tf.keras.layers.Dense(128, activation='relu'),
14
- tf.keras.layers.Dropout(0.2),
15
- tf.keras.layers.Dense(10)
16
- ])
17
-
18
- predictions = model(x_train[:1]).numpy()
19
- print(predictions)
20
-
21
- tf.nn.softmax(predictions).numpy()
22
-
23
- loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
24
- loss_fn(y_train[:1], predictions).numpy()
25
-
26
- model.compile(optimizer='adam',
27
- loss=loss_fn,
28
- metrics=['accuracy'])
29
-
30
-
31
- model.fit(x_train, y_train, epochs=5)
32
- model.evaluate(x_test, y_test, verbose=2)
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
- def greet(name):
50
- return f"Hello, {name}!"
51
-
52
- iface = gr.Interface(greet, "text", "text")
53
- iface.launch()
54
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import tensorflow as tf
3
 
4
+ # Create a Gradio App using Blocks
5
+ with gr.Blocks() as demo:
6
+ gr.Markdown(
7
+ """
8
+ # Welcome to the Virtual Therapist Chat Bot!
9
+ """
10
+ )
11
+ with gr.Accordion("Click for Instructions:"):
12
+ gr.Markdown(
13
+ """
14
+ * Tell the therapist your problems, by recording your query.
15
+ * Submit your query, and follow the chat or listen to the Therapists advice.
16
+ * When you are ready to respond, clear your last recording and resubmit.
17
+ note: Transcribe Audio does not work on iOS
18
+ """)
19
+ def modelTraining():
20
+
21
+
22
+ print("TensorFlow version:", tf.__version__)
23
+
24
+ mnist = tf.keras.datasets.mnist
25
+
26
+ (x_train, y_train), (x_test, y_test) = mnist.load_data()
27
+ x_train, x_test = x_train / 255.0, x_test / 255.0
28
+
29
+ model = tf.keras.models.Sequential([
30
+ tf.keras.layers.Flatten(input_shape=(28, 28)),
31
+ tf.keras.layers.Dense(128, activation='relu'),
32
+ tf.keras.layers.Dropout(0.2),
33
+ tf.keras.layers.Dense(10)
34
+ ])
35
+
36
+ predictions = model(x_train[:1]).numpy()
37
+ print(predictions)
38
+
39
+ tf.nn.softmax(predictions).numpy()
40
+
41
+ loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
42
+ loss_fn(y_train[:1], predictions).numpy()
43
+
44
+ model.compile(optimizer='adam',
45
+ loss=loss_fn,
46
+ metrics=['accuracy'])
47
+
48
+
49
+ model.fit(x_train, y_train, epochs=5)
50
+ model.evaluate(x_test, y_test, verbose=2)
51
+
52
+ return "done"
53
+
54
+
55
+ # Creates the Gradio interface objects
56
+ # The submit button triggers a cascade of
57
+ # events that each engage a different
58
+ # component as input/output
59
+ with gr.Row():
60
+ with gr.Column(scale=1):
61
+ submit_btn = gr.Button(value="Train/Eval")
62
+ with gr.Column(scale=2):
63
+ model_data = gr.Text(label="Model Results", interactive=False)
64
+ submit_btn.click(modelTraining, [], user_transcript)
65
+
66
+
67
+ # creates a local web server
68
+ # if share=True creates a public
69
+ # demo on huggingface.co
70
+ demo.launch(share=False)