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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -13
app.py CHANGED
@@ -12,7 +12,6 @@ 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
- import tensorflow_addons as tfa
16
 
17
  # Load the pre-trained model and tokenizer
18
  model = tf.keras.models.load_model('baseline.h5')
@@ -36,23 +35,18 @@ def classify_comment(comment):
36
  predictions = model.predict(comment_sequence)[0]
37
  results = dict(zip(labels, predictions))
38
 
39
- max_value = max(results.values())
 
40
 
41
- max_keys = [key for key, value in results.items() if value == max_value]
42
-
43
- return max_keys[0].capitalize()
44
-
45
- # Create the Gradio interface
46
- comment_input = gr.inputs.Textbox(label="Enter your comment here")
47
- output_text = gr.outputs.Textbox(label="Classification Results")
48
 
 
49
  iface = gr.Interface(
50
  fn=classify_comment,
51
- inputs=comment_input,
52
- outputs=output_text,
53
  live=True # Set to True for live updates without needing to restart the server
54
  )
55
 
56
  # Launch the Gradio app
57
- iface.launch()
58
-
 
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
  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
 
51
  # Launch the Gradio app
52
+ iface.launch()