edemgold commited on
Commit
4f22934
1 Parent(s): 8016856

Add application file

Browse files
Files changed (2) hide show
  1. app.py +46 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ #Importing dependancies
3
+ from styleformer import Styleformer
4
+ import gradio as gr
5
+ import torch
6
+ import warnings
7
+ warnings.filterwarnings("ignore")
8
+
9
+ def set_seed(seed):
10
+ torch.manual_seed(seed)
11
+ if torch.cuda.is_available():
12
+ torch.cuda.manual_seed_all(seed)
13
+
14
+ set_seed(1234)
15
+
16
+ #Casual-Formal
17
+ sf_0 = Styleformer(style=0)
18
+
19
+ #Formal-Casual
20
+ sf_1 = Styleformer(style=1)
21
+
22
+ #Active-Passive
23
+ sf_2 = Styleformer(style=2)
24
+
25
+ #Passive-Active
26
+ sf_3 = Styleformer(style=3)
27
+
28
+ def func(text, tone):
29
+ if tone=="Casual-Formal":
30
+ return sf_0.transfer(text)
31
+ if tone=="Formal-Casual":
32
+ return sf_1.transfer(text)
33
+ if tone=="Active-Passive":
34
+ return sf_2.transfer(text)
35
+ if tone=="Passive-Active":
36
+ return sf_3.transfer(text)
37
+ else:
38
+ return "No available Transfers😭"
39
+
40
+ #Initalizing Gradio App
41
+ app_description = "This model transforms the tone of text, from formal to informal, from Active to Passive. Choose your option below."
42
+ app_title = "Tone Transfer"
43
+
44
+ app = gr.Interface(func,["text",gr.inputs.Radio(["Casual-Formal", "Formal-Casual", "Active-Passive","Passive-Active"])],"text",description=app_description, title=app_title)
45
+
46
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/PrithivirajDamodaran/Styleformer.git
2
+ torch