Spaces:
Runtime error
Runtime error
Commit
·
a26068c
1
Parent(s):
57c5b24
created topic.py
Browse files
topics.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
def load_topic_transfomers():
|
4 |
+
from transformers import pipeline
|
5 |
+
try:
|
6 |
+
topic_classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli",device="cuda", compute_type="float16")
|
7 |
+
except Exception as e:
|
8 |
+
topic_classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
9 |
+
print("Error: ", e)
|
10 |
+
return topic_classifier
|
11 |
+
|
12 |
+
def suggest_topic(text):
|
13 |
+
|
14 |
+
while len(text)> 1024:
|
15 |
+
text = summarize(whole_text[:-10])
|
16 |
+
|
17 |
+
possible_topics = ["Gadgets", 'Business','Finance', 'Health', 'Sports', 'Politics','Government','Science','Education', 'Travel', 'Tourism', 'Finance & Economics','Market','Technology','Scientific Discovery',
|
18 |
+
'Entertainment','Environment','News & Media' "Space,Universe & Cosmos", "Fashion", "Manufacturing and Constructions","Law & Crime","Motivation", "Development & Socialization", "Archeology"]
|
19 |
+
|
20 |
+
result = topic_classifier(text, possible_topics)
|
21 |
+
|
22 |
+
return result['labels']
|
23 |
+
|
24 |
+
st.title("Topic Suggestion")
|
25 |
+
with st.spinner(Loading Model):
|
26 |
+
topic_classifier = load_topic_transfomers()
|
27 |
+
st.success(Model_loaded)
|
28 |
+
|
29 |
+
whole_text = st.text_input("Enter the text Here: ")
|
30 |
+
predicted_topic = suggest_topic(whole_text)
|
31 |
+
|
32 |
+
st.write('Suggested Topics')
|
33 |
+
for i in predicted_topic:
|
34 |
+
st.write(i)
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|