Spaces:
Runtime error
Runtime error
File size: 1,702 Bytes
9bf0a82 4947e7b 3489839 9bf0a82 f16722b 4947e7b f16722b 655fd42 2e8ee0a a9c5bc3 f16722b a9c5bc3 655fd42 f5649ba 655fd42 d76d248 06e3643 980767f 655fd42 980767f 2e8ee0a 06e3643 f16722b |
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 |
import streamlit as st
from transformers import (AutoModel, AutoTokenizer, pipeline, T5ForConditionalGeneration)
# import torch
st.set_page_config(layout="wide", page_title="تبدیل متون محاورهای به فارسی")
model_path = 'erfan226/persian-t5-formality-transfer'
model = T5ForConditionalGeneration.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
pipe = pipeline(task='text2text-generation', model=model, tokenizer=tokenizer)
def paraphrase(text, num_outputs, n_beams, min_len, max_len):
# for j in range(3):
out = pipe(text, num_return_sequences=num_outputs, encoder_no_repeat_ngram_size=4, do_sample=True, num_beams=n_beams, max_length=max_len)
return out
text = st.text_area('متن محاورهای خود را در این کادر وارد نمائید:', "من با دوستام میرم بازی", height=50)
num_outputs = st.sidebar.slider('تعداد خروجی', min_value=1, max_value=10, value=3, step=1)
num_beams = st.sidebar.slider('طول Beam', min_value=1, max_value=10, value=5, step=1)
min_length = st.sidebar.slider('حداقل طول جمله', min_value=10, max_value=100, value=30, step=5)
max_length = st.sidebar.slider('حداکثر طول طول جمله', min_value=30, max_value=128, value=100, step=5)
button = st.button("تبدیل متن")
with st.spinner("در حال تبدیل متن..."):
if button and text:
out = paraphrase(text,num_outputs, num_beams, min_length, max_length)
st.markdown("**متن خروجی:**")
for i, txt in enumerate(out):
st.write(out[i]['generated_text'])
# x = st.slider('Select a value')
# st.write(x, 'squared is', x * x) |