Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,15 +4,21 @@ from bertopic import BERTopic
|
|
4 |
|
5 |
topic_model = BERTopic.load("TarekAi/ArBERTopic")
|
6 |
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
outputs=gr.Textbox(lines=2, label="Text Classification Result"),
|
14 |
-
title="Text Classification",
|
15 |
-
description="Enter a text and see the text classification result!",
|
16 |
-
examples=examples)
|
17 |
-
|
18 |
-
io.launch()
|
|
|
4 |
|
5 |
topic_model = BERTopic.load("TarekAi/ArBERTopic")
|
6 |
|
7 |
+
def predict_topic(document):
|
8 |
+
topics, probabilities = topic_model.transform([document])
|
9 |
+
return {"Predicted Topic": topics[0], "Probabilities": probabilities[0].tolist()}
|
10 |
|
11 |
+
# Create the Gradio interface
|
12 |
+
iface = gr.Interface(
|
13 |
+
fn=predict_topic,
|
14 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter your idea here..."),
|
15 |
+
outputs=[
|
16 |
+
gr.outputs.Textbox(label="Predicted Topic"),
|
17 |
+
gr.outputs.Label(label="Topic Probabilities")
|
18 |
+
],
|
19 |
+
title="BERTopic Inference",
|
20 |
+
description="Enter a single idea to get the predicted topic and its probabilities."
|
21 |
+
)
|
22 |
|
23 |
+
# Launch the interface
|
24 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|