yangxinsci1993 commited on
Commit
eafc169
1 Parent(s): 196c0a9
Files changed (2) hide show
  1. app.py +13 -1
  2. requirements.txt +2 -0
app.py CHANGED
@@ -1,8 +1,8 @@
 
1
  from transformers import pipeline
2
  from transformers import AutoModelForSeq2SeqLM
3
  from transformers import AutoTokenizer
4
 
5
-
6
  # Load trained model
7
  model = AutoModelForSeq2SeqLM.from_pretrained("/output/reframer")
8
  tokenizer = AutoTokenizer.from_pretrained("/output/reframer")
@@ -11,6 +11,18 @@ reframer = pipeline('summarization', model=model, tokenizer=tokenizer)
11
 
12
  def reframe(text, strategy):
13
  text_with_strategy = text + "Strategy: ['" + strategy + "']"
 
 
 
 
 
 
 
 
 
 
 
 
14
  return reframer(text_with_strategy)[0]['summary_text']
15
 
16
 
 
1
+ import torch
2
  from transformers import pipeline
3
  from transformers import AutoModelForSeq2SeqLM
4
  from transformers import AutoTokenizer
5
 
 
6
  # Load trained model
7
  model = AutoModelForSeq2SeqLM.from_pretrained("/output/reframer")
8
  tokenizer = AutoTokenizer.from_pretrained("/output/reframer")
 
11
 
12
  def reframe(text, strategy):
13
  text_with_strategy = text + "Strategy: ['" + strategy + "']"
14
+ #Input Control
15
+ #The input text cannot be too short to ensure it has substantial content to be reframed. It also cannot be too long to ensure the text has a focused idea.
16
+ if len(text) < 15 or len(text) > 150:
17
+ return "Please try again by inputing text with moderate length."
18
+ if TextBlob(text).sentiment.polarity > 0.2:
19
+ return "Please try again by inputing text that is negative."
20
+ from hatesonar import Sonar
21
+ sonar = Sonar()
22
+ if sonar.ping(text)['classes'][1]['confidence'] > 0.8:
23
+ return "Please try again by not inputing offensive language."
24
+ #if TextBlob(text).sentiment.polarity > 0:
25
+ # return "Please try again by inputing text that is negative."
26
  return reframer(text_with_strategy)[0]['summary_text']
27
 
28
 
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  gradio==3.3.1
 
 
2
  transformers==4.10.0
 
1
  gradio==3.3.1
2
+ hatesonar==0.0.7
3
+ torch==1.8.0
4
  transformers==4.10.0