Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,54 +1,70 @@
|
|
1 |
import gradio as gr
|
2 |
import tensorflow as tf
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
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)
|