File size: 1,394 Bytes
58c96a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from styleformer import Styleformer
import torch
import warnings

warnings.filterwarnings("ignore")
import gradio as gr



def para1(choices = "Active to passive", source_sentences):
    
        sf = Styleformer(style=2)
        sentance1 = list(source_sentences.split("."))
        output_sentance = []
        for source_sentence in sentance1:
            target_sentence = sf.transfer(source_sentence)
            if target_sentence is not None:
                output_sentance.append(target_sentence)
                #print(target_sentence)
            else:
                output_sentance.append(target_sentence)
                #print(target_sentence)
                output_sentance.append(target_sentence)
        res = [i for i in output_sentance if i is not None]
        #print(output_sentance)
        #print(res)
        final = ""
        for value in res:
            joint_value = "".join(value)
            if final == "":
                final += joint_value
            else:
                final = f"{final}.{joint_value}"
        final = final.replace("..", ".")
        new_output = final.replace('Active to passive:', "")
        #print(final)
        return new_output

input_2 = gr.inputs.Textbox(placeholder='Enter your text here...', label='Input')

iface = gr.Interface(input_2, "text", theme='huggingface')
if __name__ == "__main__":
    iface.launch(debug=True)