Active / app.py
jaimin's picture
Create app.py
58c96a8
raw
history blame
1.43 kB
from styleformer import Styleformer
import torch
import warnings
warnings.filterwarnings("ignore")
import gradio as gr
def para1(choices = "Active to passive", source_sentences):
if choices == "Active to passive":
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)