MYox commited on
Commit
8bab87a
·
1 Parent(s): f0bacc3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from nltk.tokenize import sent_tokenize
2
+ from setfit import SetFitModel
3
+ import gradio as gr
4
+
5
+ inf_model = SetFitModel.from_pretrained('multi-label_8_sent_v3_1')
6
+
7
+ features = (['Teaching & learning', 'Support', 'Communication', 'Organisation & timetable',
8
+ 'Assessment & feedback', 'Career & placement', 'Health, well-being & social life', 'Facilities & technology'])
9
+
10
+ def get_doc_topics_old(d):
11
+ t = inf_model(d)
12
+ return [f for i, f in enumerate(features) if t[0][i]]
13
+
14
+
15
+ def get_comment_topics_old(comment):
16
+ sent_topics = []
17
+ for s in sent_tokenize(comment):
18
+ sent_topics.append(get_doc_topics_old([s]))
19
+
20
+ output = []
21
+ for x in sent_topics:
22
+ for y in x:
23
+ if y not in output:
24
+ output.append(y)
25
+ return ', '.join(output)
26
+
27
+ app = gr.Interface(
28
+ fn = get_comment_topics_old,
29
+ inputs=gr.Textbox(lines=4, placeholder='Type comment here'),
30
+ outputs=gr.Textbox(lines=4),
31
+ allow_flagging='never',
32
+ examples = ([["Lots of support, especially when revising for exams. Lecturers always respond to emails very quickly!"],
33
+ ["Loved everything. Met lots of new people and really enjoyed placements."],
34
+ ["I thoughts the lectures were sometimes boring but the library was great!"]
35
+ ])
36
+ )
37
+ app.queue()
38
+ app.launch()