sukh28 commited on
Commit
d4ecc33
1 Parent(s): 523f901

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -7,11 +7,18 @@ Original file is located at
7
  https://colab.research.google.com/drive/1OQvi3I_q3WfavYBpjovCYfv2SPYt__pF
8
  """
9
 
 
 
 
 
 
 
10
  import json
11
  import gradio as gr
12
  import tensorflow as tf
13
  from tensorflow.keras.models import load_model
14
  from tensorflow.keras.preprocessing.text import tokenizer_from_json
 
15
 
16
  # Load the pre-trained model and tokenizer
17
  model = tf.keras.models.load_model('baseline.h5')
@@ -35,16 +42,20 @@ def classify_comment(comment):
35
  predictions = model.predict(comment_sequence)[0]
36
  results = dict(zip(labels, predictions))
37
 
38
- max_class = max(results, key=results.get)
39
- max_value = results[max_class]
 
 
 
40
 
41
- return {"Label": max_class.capitalize(), "Confidence": f"{max_value:.2%}"}
 
 
42
 
43
- # Create the Gradio interface with an improved layout
44
  iface = gr.Interface(
45
  fn=classify_comment,
46
- inputs=gr.inputs.Textbox(label="Enter your comment here", lines=5),
47
- outputs=gr.outputs.Label(num_top_classes=1, label="Predicted Label", type="auto"),
48
  live=True # Set to True for live updates without needing to restart the server
49
  )
50
 
 
7
  https://colab.research.google.com/drive/1OQvi3I_q3WfavYBpjovCYfv2SPYt__pF
8
  """
9
 
10
+ """gradio_app.py
11
+ Automatically generated by Colaboratory.
12
+ Original file is located at
13
+ https://colab.research.google.com/drive/1OQvi3I_q3WfavYBpjovCYfv2SPYt__pF
14
+ """
15
+
16
  import json
17
  import gradio as gr
18
  import tensorflow as tf
19
  from tensorflow.keras.models import load_model
20
  from tensorflow.keras.preprocessing.text import tokenizer_from_json
21
+ import tensorflow_addons as tfa
22
 
23
  # Load the pre-trained model and tokenizer
24
  model = tf.keras.models.load_model('baseline.h5')
 
42
  predictions = model.predict(comment_sequence)[0]
43
  results = dict(zip(labels, predictions))
44
 
45
+ max_value = max(results.values())
46
+
47
+ max_keys = [key for key, value in results.items() if value == max_value]
48
+
49
+ return max_keys[0].capitalize()
50
 
51
+ # Create the Gradio interface
52
+ comment_input = gr.inputs.Textbox(label="Enter your comment here")
53
+ output_text = gr.outputs.Textbox(label="Classification Results")
54
 
 
55
  iface = gr.Interface(
56
  fn=classify_comment,
57
+ inputs=comment_input,
58
+ outputs=output_text,
59
  live=True # Set to True for live updates without needing to restart the server
60
  )
61