import gradio as gr from transformers import pipeline from transformers import pipeline import re dante = pipeline('text-generation',model='.', tokenizer='GroNLP/gpt2-small-italian-embeddings') def grammatical_cleaning(generated: str) -> str: generated = re.sub("\.[^\s]",". ", generated) generated = re.sub("\,[^\s]",", ", generated) generated = re.sub("\;[^\s]","; ", generated) generated = re.sub("\:[^\s]",": ", generated) generated = re.sub("\![^\s]","! ", generated) generated = list(generated) for n in range(len(generated)-2): if generated[n]=="." or generated[n]=="?": if generated[n+1].islower() and generated[n+1].isalpha(): generated[n+1] = generated[n+1].upper() elif generated[n+2].islower() and generated[n+2].isalpha(): generated[n+2] = generated[n+2].upper() return ''.join(generated) def get_text(input): generated = dante(input, max_length=128)[0]['generated_text'] generated = grammatical_cleaning(generated) return generated inp = input() print(get_text(inp)) #iface = gr.Interface(fn=get_text, inputs="text", outputs="text") #iface.launch()