Spaces:
Running
Running
Commit
·
e6bed4b
1
Parent(s):
a2b1396
Added title generation task
Browse files- app.py +3 -1
- apps/title_generation.py +62 -0
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from transformers import pipeline
|
|
| 5 |
import apps.summarization
|
| 6 |
import apps.home
|
| 7 |
import apps.paraphrasing
|
|
|
|
| 8 |
|
| 9 |
st.set_page_config(
|
| 10 |
page_title="Turna",
|
|
@@ -15,7 +16,8 @@ st.set_page_config(
|
|
| 15 |
PAGES = {
|
| 16 |
"Turna": apps.home,
|
| 17 |
"Text Summarization": apps.summarization,
|
| 18 |
-
"Text Paraphrasing": apps.paraphrasing
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
|
|
|
|
| 5 |
import apps.summarization
|
| 6 |
import apps.home
|
| 7 |
import apps.paraphrasing
|
| 8 |
+
import apps.title_generation
|
| 9 |
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Turna",
|
|
|
|
| 16 |
PAGES = {
|
| 17 |
"Turna": apps.home,
|
| 18 |
"Text Summarization": apps.summarization,
|
| 19 |
+
"Text Paraphrasing": apps.paraphrasing,
|
| 20 |
+
"News Title Generation": apps.title_generation,
|
| 21 |
}
|
| 22 |
|
| 23 |
|
apps/title_generation.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import time
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import os
|
| 6 |
+
from .utils import query
|
| 7 |
+
|
| 8 |
+
HF_AUTH_TOKEN = os.getenv('HF_AUTH_TOKEN')
|
| 9 |
+
headers = {"Authorization": f"Bearer {HF_AUTH_TOKEN}"}
|
| 10 |
+
|
| 11 |
+
def write():
|
| 12 |
+
|
| 13 |
+
st.markdown("# News Title Generation")
|
| 14 |
+
st.sidebar.header("News Title Generation")
|
| 15 |
+
st.write(
|
| 16 |
+
"""Here, you can generate titles for your text in the news domain using the fine-tuned TURNA title generation models. """
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Sidebar
|
| 20 |
+
|
| 21 |
+
# Taken from https://huggingface.co/spaces/flax-community/spanish-gpt2/blob/main/app.py
|
| 22 |
+
st.sidebar.subheader("Configurable parameters")
|
| 23 |
+
|
| 24 |
+
model_name = st.sidebar.selectbox(
|
| 25 |
+
"Model Selector",
|
| 26 |
+
options=[
|
| 27 |
+
"turna_title_generation_tr_news",
|
| 28 |
+
"turna_title_generation_mlsum"
|
| 29 |
+
],
|
| 30 |
+
index=0,
|
| 31 |
+
)
|
| 32 |
+
max_new_tokens = st.sidebar.number_input(
|
| 33 |
+
"Maximum length",
|
| 34 |
+
min_value=0,
|
| 35 |
+
max_value=64,
|
| 36 |
+
value=64,
|
| 37 |
+
help="The maximum length of the sequence to be generated.",
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
length_penalty = st.sidebar.number_input(
|
| 41 |
+
"Length penalty",
|
| 42 |
+
value=2.0,
|
| 43 |
+
help=" length_penalty > 0.0 promotes longer sequences, while length_penalty < 0.0 encourages shorter sequences. ",
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
no_repeat_ngram_size = st.sidebar.number_input(
|
| 47 |
+
"No Repeat N-Gram Size",
|
| 48 |
+
min_value=0,
|
| 49 |
+
value=3,
|
| 50 |
+
help="If set to int > 0, all ngrams of that size can only occur once.",
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
input_text = st.text_area(label='Enter a text: ', height=100,
|
| 56 |
+
value="Kalp krizi geçirenlerin yaklaşık üçte birinin kısa bir süre önce grip atlattığı düşünülüyor. Peki grip virüsü ne yapıyor da kalp krizine yol açıyor? Karpuz şöyle açıkladı: Grip virüsü kanın yapışkanlığını veya pıhtılaşmasını artırıyor. ")
|
| 57 |
+
url = ("https://api-inference.huggingface.co/models/boun-tabi-LMG/" + model_name.lower())
|
| 58 |
+
params = {"length_penalty": length_penalty, "no_repeat_ngram_size": no_repeat_ngram_size, "max_new_tokens": max_new_tokens }
|
| 59 |
+
if st.button("Generate"):
|
| 60 |
+
with st.spinner('Generating...'):
|
| 61 |
+
output = query(input_text, url, params)
|
| 62 |
+
st.success(output)
|