Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from styleformer import Styleformer
|
2 |
+
import torch
|
3 |
+
import warnings
|
4 |
+
|
5 |
+
warnings.filterwarnings("ignore")
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
|
9 |
+
|
10 |
+
def para1(choices = "Active to passive", source_sentences):
|
11 |
+
|
12 |
+
if choices == "Active to passive":
|
13 |
+
sf = Styleformer(style=2)
|
14 |
+
sentance1 = list(source_sentences.split("."))
|
15 |
+
output_sentance = []
|
16 |
+
for source_sentence in sentance1:
|
17 |
+
target_sentence = sf.transfer(source_sentence)
|
18 |
+
if target_sentence is not None:
|
19 |
+
output_sentance.append(target_sentence)
|
20 |
+
#print(target_sentence)
|
21 |
+
else:
|
22 |
+
output_sentance.append(target_sentence)
|
23 |
+
#print(target_sentence)
|
24 |
+
output_sentance.append(target_sentence)
|
25 |
+
res = [i for i in output_sentance if i is not None]
|
26 |
+
#print(output_sentance)
|
27 |
+
#print(res)
|
28 |
+
final = ""
|
29 |
+
for value in res:
|
30 |
+
joint_value = "".join(value)
|
31 |
+
if final == "":
|
32 |
+
final += joint_value
|
33 |
+
else:
|
34 |
+
final = f"{final}.{joint_value}"
|
35 |
+
final = final.replace("..", ".")
|
36 |
+
new_output = final.replace('Active to passive:', "")
|
37 |
+
#print(final)
|
38 |
+
return new_output
|
39 |
+
|
40 |
+
input_2 = gr.inputs.Textbox(placeholder='Enter your text here...', label='Input')
|
41 |
+
|
42 |
+
iface = gr.Interface(input_2, "text", theme='huggingface')
|
43 |
+
if __name__ == "__main__":
|
44 |
+
iface.launch(debug=True)
|