Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,167 +1,3 @@
|
|
1 |
-
# import streamlit as st
|
2 |
-
# from transformers import pipeline
|
3 |
-
|
4 |
-
# class BiasAndGrammarCorrectionPipeline:
|
5 |
-
# def __init__(self, grammar_correction_pipeline, bias_detection_pipeline):
|
6 |
-
# self.grammar_correction_pipeline = grammar_correction_pipeline
|
7 |
-
# self.bias_detection_pipeline = bias_detection_pipeline
|
8 |
-
|
9 |
-
# def __call__(self, text):
|
10 |
-
# # Perform grammar correction
|
11 |
-
# corrected_text = self.grammar_correction_pipeline(text, num_beams=5, max_length=1000)[0]["generated_text"]
|
12 |
-
|
13 |
-
# # Perform bias detection
|
14 |
-
# result = self.bias_detection_pipeline(corrected_text)
|
15 |
-
|
16 |
-
# # Determine if bias is detected based on the bias score
|
17 |
-
# bias_detected = False
|
18 |
-
# bias_score = None
|
19 |
-
|
20 |
-
# if isinstance(result, list):
|
21 |
-
# for item in result:
|
22 |
-
# if "score" in item:
|
23 |
-
# if item["score"] >= 0.5:
|
24 |
-
# bias_detected = True
|
25 |
-
# bias_score = item["score"]
|
26 |
-
# break
|
27 |
-
# else:
|
28 |
-
# if "score" in result:
|
29 |
-
# bias_detected = result["score"] >= 0.5
|
30 |
-
# bias_score = result["score"]
|
31 |
-
|
32 |
-
# return corrected_text, bias_detected, bias_score
|
33 |
-
|
34 |
-
# # Load the grammar correction model pipeline
|
35 |
-
# corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
|
36 |
-
|
37 |
-
# # Load the text classification model pipeline
|
38 |
-
# classifier = pipeline("text-classification", model="Alicewuu/bias_detection", return_all_scores=True)
|
39 |
-
|
40 |
-
# # Instantiate the combined pipeline
|
41 |
-
# combined_pipeline = BiasAndGrammarCorrectionPipeline(corrector, classifier)
|
42 |
-
|
43 |
-
# # Streamlit application title
|
44 |
-
# st.title("Text Bias Detection")
|
45 |
-
# st.write("Detection for 2 classes")
|
46 |
-
|
47 |
-
# # Text input for user to enter the text to classify
|
48 |
-
# text = st.text_area("Enter the text to detect", "")
|
49 |
-
# corrected_text, bias_detected, bias_score = combined_pipeline(text)
|
50 |
-
|
51 |
-
# # Perform text classification when the user clicks the "Detect" button
|
52 |
-
# if st.button("Detect"):
|
53 |
-
# # Display the results
|
54 |
-
# st.write("Corrected Text:", corrected_text)
|
55 |
-
# st.write("Bias Detected:", bias_detected)
|
56 |
-
# if bias_score is not None:
|
57 |
-
# st.write("Bias Score:", bias_score)
|
58 |
-
|
59 |
-
|
60 |
-
# import streamlit as st
|
61 |
-
# from transformers import pipeline
|
62 |
-
# # from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
63 |
-
|
64 |
-
# class BiasAndGrammarCorrectionPipeline:
|
65 |
-
# def __init__(self, grammar_correction_pipeline, bias_detection_pipeline):
|
66 |
-
# self.grammar_correction_pipeline = grammar_correction_pipeline
|
67 |
-
# self.bias_detection_pipeline = bias_detection_pipeline
|
68 |
-
|
69 |
-
# def __call__(self, text):
|
70 |
-
# # Perform grammar correction
|
71 |
-
# corrected_text = self.grammar_correction_pipeline(text, num_beams=5, max_length=1000)[0]["generated_text"]
|
72 |
-
|
73 |
-
# # Perform bias detection
|
74 |
-
# result = self.bias_detection_pipeline(corrected_text)
|
75 |
-
# bias_score = result[0]["score"]
|
76 |
-
|
77 |
-
# # Determine if bias is detected based on the bias score
|
78 |
-
# bias_detected = bias_score >= 0.5
|
79 |
-
|
80 |
-
# return corrected_text, bias_detected, bias_score
|
81 |
-
|
82 |
-
# # Load the grammar correction model pipeline
|
83 |
-
# # tokenizer = AutoTokenizer.from_pretrained("vennify/t5-base-grammar-correction")
|
84 |
-
# # model = AutoModelForSeq2SeqLM.from_pretrained("vennify/t5-base-grammar-correction")
|
85 |
-
# # corrector = pipeline("text2text-generation", model=model, tokenizer = tokenizer)
|
86 |
-
# corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
|
87 |
-
|
88 |
-
# # Load the text classification model pipeline
|
89 |
-
# classifier = pipeline("text-classification", model="Alicewuu/bias_detection", return_all_scores=True)
|
90 |
-
|
91 |
-
# # Instantiate the combined pipeline
|
92 |
-
# combined_pipeline = BiasAndGrammarCorrectionPipeline(corrector, classifier)
|
93 |
-
|
94 |
-
# # Streamlit application title
|
95 |
-
# st.title("Text Bias Detection")
|
96 |
-
# st.write("Detection for 2 classes")
|
97 |
-
|
98 |
-
# # Text input for user to enter the text to classify
|
99 |
-
# text = st.text_area("Enter the text to detect", "")
|
100 |
-
|
101 |
-
# # Perform text classification when the user clicks the "Classify" button
|
102 |
-
# if st.button("Detect"):
|
103 |
-
|
104 |
-
# corrected_text, bias_detected, bias_score = combined_pipeline(text)
|
105 |
-
|
106 |
-
# # Display the classification result
|
107 |
-
# st.write("The text with correct grammar:", corrected_text)
|
108 |
-
# st.write("Biased:", bias_detected)
|
109 |
-
# st.write("Score:", bias_score)
|
110 |
-
|
111 |
-
# # Perform text classification on the input text
|
112 |
-
# results = classifier(text)[0]
|
113 |
-
|
114 |
-
# # Find the label with the highest score
|
115 |
-
# max_label = max(results, key=lambda x: x['score'])
|
116 |
-
|
117 |
-
# # Display the classification result
|
118 |
-
# st.write("Text:", text)
|
119 |
-
# st.write("Label:", max_label['label'])
|
120 |
-
# st.write("Score:", max_label['score'])
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
# import streamlit as st
|
125 |
-
# from transformers import pipeline
|
126 |
-
|
127 |
-
# # Load the grammar correction model pipeline
|
128 |
-
# corrector = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
|
129 |
-
|
130 |
-
# # Load the text classification model pipeline
|
131 |
-
# classifier = pipeline("text-classification", model="Alicewuu/bias_detection", return_all_scores=True)
|
132 |
-
|
133 |
-
# # Function to perform bias and grammar correction detection
|
134 |
-
# def detect_bias_and_grammar_correction(text):
|
135 |
-
# # Perform grammar correction
|
136 |
-
# corrected_text = corrector(text, num_beams=5, max_length=1000)[0]["generated_text"]
|
137 |
-
|
138 |
-
# # Perform bias detection
|
139 |
-
# result = classifier(corrected_text)
|
140 |
-
# bias_score = result[0][0]["score"]
|
141 |
-
|
142 |
-
# # Determine if bias is detected based on the bias score
|
143 |
-
# bias_detected = bias_score >= 0.5
|
144 |
-
|
145 |
-
# return corrected_text, bias_detected, bias_score
|
146 |
-
|
147 |
-
# # Streamlit application title
|
148 |
-
# st.title("Text Bias Detection")
|
149 |
-
# st.write("Detection for 2 classes")
|
150 |
-
|
151 |
-
# # Text input for user to enter the text to classify
|
152 |
-
# text = st.text_area("Enter the text to detect", "")
|
153 |
-
|
154 |
-
# # Perform text classification when the user clicks the "Detect" button
|
155 |
-
# if st.button("Detect"):
|
156 |
-
# corrected_text, bias_detected, bias_score = detect_bias_and_grammar_correction(text)
|
157 |
-
|
158 |
-
# # Display the classification result
|
159 |
-
# st.write("The text with correct grammar:", corrected_text)
|
160 |
-
# st.write("Biased:", bias_detected)
|
161 |
-
# st.write("Score:", bias_score)
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
import streamlit as st
|
166 |
from transformers import pipeline
|
167 |
|
@@ -193,5 +29,3 @@ if st.button("Detect"):
|
|
193 |
st.write("The text with correct grammar:", corrected_text)
|
194 |
st.write("Biased:", bias_detected)
|
195 |
st.write("Score:", bias_score)
|
196 |
-
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
|
|
29 |
st.write("The text with correct grammar:", corrected_text)
|
30 |
st.write("Biased:", bias_detected)
|
31 |
st.write("Score:", bias_score)
|
|
|
|