taitbaha commited on
Commit
e025580
1 Parent(s): 1fed686

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -4,15 +4,21 @@ from bertopic import BERTopic
4
 
5
  topic_model = BERTopic.load("TarekAi/ArBERTopic")
6
 
7
- topic, prob = topic_model.transform("عدم إنجاز الواجبات المدرسية")
 
 
8
 
9
- examples=["عدم الالتزام بالتشريع المنظم للحياة المدرسية من طرف الاستاذ", "عدم إنجاز الواجبات المدرسية"]
 
 
 
 
 
 
 
 
 
 
10
 
11
- io = gr.Interface(fn=text_classification,
12
- inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter your idea here..."),
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()