Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,18 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
-
pipe = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def predict(input_txt):
|
| 8 |
-
predictions = pipe(input_txt)
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
gradio_app = gr.Interface(
|
| 12 |
predict,
|
|
@@ -15,7 +21,5 @@ gradio_app = gr.Interface(
|
|
| 15 |
title="NSFW Prediction",
|
| 16 |
)
|
| 17 |
|
| 18 |
-
#gradio_app = gr.Interface.from_pipeline(pipe)
|
| 19 |
-
|
| 20 |
if __name__ == "__main__":
|
| 21 |
-
gradio_app.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
pipe = pipeline(
|
| 5 |
+
task="text-classification",
|
| 6 |
+
model="TostAI/nsfw-text-detection-large",
|
| 7 |
+
return_all_scores=True
|
| 8 |
+
)
|
| 9 |
|
| 10 |
def predict(input_txt):
|
| 11 |
+
predictions = pipe(input_txt)[0] # Get first (and only) result
|
| 12 |
+
|
| 13 |
+
# Convert list of dicts to a single dict
|
| 14 |
+
result = {pred['label']: pred['score'] for pred in predictions}
|
| 15 |
+
return result
|
| 16 |
|
| 17 |
gradio_app = gr.Interface(
|
| 18 |
predict,
|
|
|
|
| 21 |
title="NSFW Prediction",
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
| 24 |
if __name__ == "__main__":
|
| 25 |
+
gradio_app.launch()
|