sgurriah commited on
Commit
164053e
β€’
1 Parent(s): 87b9e49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -10
app.py CHANGED
@@ -1,17 +1,28 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- model_name = "ieuniversity/flirty_classifier"
5
- classifier = pipeline("text-classification", model=model_name)
6
 
7
- def classify_text(text):
8
- output = classifier(text)
9
- label = output[0]["label"]
10
- score = output[0]["score"]
11
- return label
12
 
13
- gr.Interface(fn=classify_text,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  inputs="text",
15
  outputs="text",
16
- title="Flirty Classifier",
17
- description="Enter some text and get a prediction for whether it's flirty or not.").launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ classifier_model_name = "ieuniversity/flirty_classifier"
5
+ paraphraser_model_name = "ieuniversity/flirty_paraphraser"
6
 
7
+ classifier = pipeline("text-classification", model=classifier_model_name)
8
+ paraphraser = pipeline("text2text-generation", model=paraphraser_model_name)
 
 
 
9
 
10
+ def classify_and_paraphrase_text(text):
11
+ classification_output = classifier(text)
12
+ label = classification_output[0]["label"]
13
+ score = classification_output[0]["score"]
14
+
15
+ if label == "flirty":
16
+ paraphrase_output = paraphraser(text, max_length=100, do_sample=True, temperature=0.8)
17
+ paraphrase_text = paraphrase_output[0]["generated_text"]
18
+ return f"This message seems flirty. Here's another suggestion: '{paraphrase_text}'"
19
+ else:
20
+ paraphrase_output = paraphraser(text, max_length=100, do_sample=True, temperature=0.8)
21
+ paraphrase_text = paraphrase_output[0]["generated_text"]
22
+ return f"This message doesn't seem flirty. How about: '{paraphrase_text}'?"
23
+
24
+ gr.Interface(fn=classify_and_paraphrase_text,
25
  inputs="text",
26
  outputs="text",
27
+ title="Flirty Classifier and Paraphraser",
28
+ description="Enter some text and get a prediction for whether it's flirty or not. If it's not flirty, get a paraphrased suggestion.").launch()