Spaces:
Runtime error
Runtime error
Add PSFT Model
Browse files
app.py
CHANGED
@@ -1,4 +1,22 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import (T5ForConditionalGeneration, AutoTokenizer, pipeline)
|
3 |
+
import torch
|
4 |
|
5 |
+
model_path = 'erfan226/persian-t5-formality-transfer'
|
6 |
+
model = T5ForConditionalGeneration.from_pretrained(model_path)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
8 |
+
pipe = pipeline(task='text2text-generation', model=model, tokenizer=tokenizer)
|
9 |
+
|
10 |
+
def paraphrase(text):
|
11 |
+
for j in range(3):
|
12 |
+
out = pipe(text, encoder_no_repeat_ngram_size=4, do_sample=True, num_beams=5, max_length=128)[0]['generated_text']
|
13 |
+
print("Paraphrase:", out)
|
14 |
+
|
15 |
+
link = st.text_area('Paste your link here...', "من با دوستام میرم بازی", height=50)
|
16 |
+
min_length = st.sidebar.slider('حداقل طول جمله', min_value=10, max_value=100, value=50, step=10)
|
17 |
+
max_length = st.sidebar.slider('حداکثر طول طول جمله', min_value=30, max_value=700, value=100, step=10)
|
18 |
+
num_beams = st.sidebar.slider('طول Beam', min_value=1, max_value=10, value=5, step=1)
|
19 |
+
out = paraphrase(link)
|
20 |
+
st.write(out)
|
21 |
+
# x = st.slider('Select a value')
|
22 |
+
# st.write(x, 'squared is', x * x)
|