Daraphan commited on
Commit
6999052
Β·
verified Β·
1 Parent(s): 6b8b191

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -62
app.py DELETED
@@ -1,62 +0,0 @@
1
- import zipfile
2
- import os
3
- import gradio as gr
4
- import tensorflow as tf
5
- from transformers import BertTokenizer, TFBertForSequenceClassification
6
- import numpy as np
7
-
8
- # Unzip model.zip if not already extracted
9
- if not os.path.exists("model"):
10
- with zipfile.ZipFile("model.zip", 'r') as zip_ref:
11
- zip_ref.extractall("model")
12
-
13
- # Correct Model Path
14
- MODEL_PATH = "model"
15
-
16
- # Load model and tokenizer
17
- model = TFBertForSequenceClassification.from_pretrained(MODEL_PATH)
18
- tokenizer = BertTokenizer.from_pretrained(MODEL_PATH)
19
-
20
- # Prediction function
21
- def predict_value(text, reason, threshold=0.7):
22
- combined_text = text + " [SEP] " + reason
23
- encoding = tokenizer(combined_text, padding="max_length", truncation=True, max_length=128, return_tensors="tf")
24
-
25
- logits = model.predict(dict(encoding)).logits
26
- probs = tf.nn.softmax(logits, axis=1).numpy()
27
-
28
- prediction = 1 if probs[:, 1] > threshold else 0
29
- confidence = probs[:, 1][0]
30
-
31
- if prediction == 1:
32
- result = "βœ… Valuable Feedback"
33
- else:
34
- result = "❌ Not Valuable Feedback"
35
-
36
- return result, f"Confidence Score: {confidence:.2f}"
37
-
38
- # Gradio UI
39
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
40
- gr.Markdown(
41
- """
42
- # πŸš€ Text & Reason Evaluator
43
- Analyze if the provided text and reason are valuable!
44
- """
45
- )
46
-
47
- with gr.Row():
48
- text_input = gr.Textbox(label="πŸ“ Enter the Text")
49
- reason_input = gr.Textbox(label="πŸ’‘ Enter the Reason")
50
-
51
- predict_button = gr.Button("πŸ” Predict")
52
-
53
- output_result = gr.Textbox(label="Result")
54
- output_confidence = gr.Textbox(label="Confidence Score")
55
-
56
- predict_button.click(
57
- predict_value,
58
- inputs=[text_input, reason_input],
59
- outputs=[output_result, output_confidence],
60
- )
61
-
62
- demo.launch()