Spaces:
Running
Running
Commit
·
5dc09e9
1
Parent(s):
94c4b32
Added summarization
Browse files- pages/turna.py → Turna.py +39 -9
- app.py +0 -31
- pages/Summarization.py +34 -0
- requirements.txt +2 -1
pages/turna.py → Turna.py
RENAMED
|
@@ -1,12 +1,18 @@
|
|
| 1 |
-
import
|
| 2 |
import streamlit as st
|
| 3 |
-
import
|
|
|
|
|
|
|
| 4 |
|
| 5 |
API_URL = "https://api-inference.huggingface.co/models/boun-tabi-LMG/TURNA"
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
"""
|
| 11 |
<h1 style="text-align:left;">TURNA</h1>
|
| 12 |
""",
|
|
@@ -22,10 +28,10 @@ def write():
|
|
| 22 |
st.markdown(
|
| 23 |
"""
|
| 24 |
|
| 25 |
-
<h3 style="text-align:
|
| 26 |
|
| 27 |
-
<p style="text-align:
|
| 28 |
-
<p style="text-align:
|
| 29 |
<p style="text-align:right;"><p>
|
| 30 |
""",
|
| 31 |
unsafe_allow_html=True,
|
|
@@ -33,14 +39,15 @@ def write():
|
|
| 33 |
|
| 34 |
#st.title('Turkish Language Generation')
|
| 35 |
#st.write('...with Turna')
|
| 36 |
-
|
| 37 |
value="Türkiye'nin başkeni neresidir?")
|
| 38 |
if st.button("Generate"):
|
| 39 |
with st.spinner('Generating...'):
|
| 40 |
-
output = query(
|
| 41 |
st.success(output)
|
| 42 |
|
| 43 |
def query(payload):
|
|
|
|
| 44 |
while True:
|
| 45 |
response = requests.post(API_URL, json=payload)
|
| 46 |
if 'error' not in response.json():
|
|
@@ -50,3 +57,26 @@ def query(payload):
|
|
| 50 |
time.sleep(15)
|
| 51 |
print('Sending request again', flush=True)
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import awesome_streamlit as ast
|
| 2 |
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
import pages.turna
|
| 6 |
|
| 7 |
API_URL = "https://api-inference.huggingface.co/models/boun-tabi-LMG/TURNA"
|
| 8 |
|
| 9 |
+
st.set_page_config(
|
| 10 |
+
page_title="Turna",
|
| 11 |
+
page_icon="📖",
|
| 12 |
+
layout='wide'
|
| 13 |
+
)
|
| 14 |
|
| 15 |
+
st.markdown(
|
| 16 |
"""
|
| 17 |
<h1 style="text-align:left;">TURNA</h1>
|
| 18 |
""",
|
|
|
|
| 28 |
st.markdown(
|
| 29 |
"""
|
| 30 |
|
| 31 |
+
<h3 style="text-align:right;">TURNA is a Turkish encoder-decoder language model.</h3>
|
| 32 |
|
| 33 |
+
<p style="text-align:right;"><p>
|
| 34 |
+
<p style="text-align:right;">Use the generation paramters on the sidebar to adjust generation quality.</p>
|
| 35 |
<p style="text-align:right;"><p>
|
| 36 |
""",
|
| 37 |
unsafe_allow_html=True,
|
|
|
|
| 39 |
|
| 40 |
#st.title('Turkish Language Generation')
|
| 41 |
#st.write('...with Turna')
|
| 42 |
+
input_text = st.text_area(label='Enter a text: ', height=100,
|
| 43 |
value="Türkiye'nin başkeni neresidir?")
|
| 44 |
if st.button("Generate"):
|
| 45 |
with st.spinner('Generating...'):
|
| 46 |
+
output = query(input_text)
|
| 47 |
st.success(output)
|
| 48 |
|
| 49 |
def query(payload):
|
| 50 |
+
#{"inputs": payload, ""}
|
| 51 |
while True:
|
| 52 |
response = requests.post(API_URL, json=payload)
|
| 53 |
if 'error' not in response.json():
|
|
|
|
| 57 |
time.sleep(15)
|
| 58 |
print('Sending request again', flush=True)
|
| 59 |
|
| 60 |
+
def pipe():
|
| 61 |
+
pipe = pipeline("text2text-generation", model="boun-tabi-LMG/TURNA", tokenizer="boun-tabi-LMG/TURNA", temperature=0.7, repetition_penalty=0.5, top_p=0.9)
|
| 62 |
+
|
| 63 |
+
"""PAGES = {
|
| 64 |
+
"Turkish Language Generation": pages.turna,
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
st.sidebar.title("Navigation")
|
| 68 |
+
selection = st.sidebar.radio("Pages", list(PAGES.keys()))
|
| 69 |
+
|
| 70 |
+
page = PAGES[selection]
|
| 71 |
+
# with st.spinner(f"Loading {selection} ..."):
|
| 72 |
+
ast.shared.components.write_page(page)"""
|
| 73 |
+
|
| 74 |
+
st.sidebar.header("Info")
|
| 75 |
+
|
| 76 |
+
st.sidebar.write(
|
| 77 |
+
"Models are available on [HF Hub](https://huggingface.co/collections/boun-tabi-LMG)"
|
| 78 |
+
)
|
| 79 |
+
st.sidebar.write(
|
| 80 |
+
"Model source code available on [GitHub](https://github.com/boun-tabi-LMG/turkish-lm-tuner)"
|
| 81 |
+
)
|
| 82 |
+
|
app.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
import awesome_streamlit as ast
|
| 2 |
-
import streamlit as st
|
| 3 |
-
|
| 4 |
-
import pages.turna
|
| 5 |
-
|
| 6 |
-
st.set_page_config(
|
| 7 |
-
page_title="About Turna",
|
| 8 |
-
page_icon="📖",
|
| 9 |
-
layout='wide'
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
PAGES = {
|
| 13 |
-
"Turkish Language Generation": pages.turna,
|
| 14 |
-
}
|
| 15 |
-
|
| 16 |
-
st.sidebar.title("Navigation")
|
| 17 |
-
selection = st.sidebar.radio("Pages", list(PAGES.keys()))
|
| 18 |
-
|
| 19 |
-
page = PAGES[selection]
|
| 20 |
-
# with st.spinner(f"Loading {selection} ..."):
|
| 21 |
-
ast.shared.components.write_page(page)
|
| 22 |
-
|
| 23 |
-
st.sidebar.header("Info")
|
| 24 |
-
|
| 25 |
-
st.sidebar.write(
|
| 26 |
-
"Models are available on [HF Hub](https://huggingface.co/collections/boun-tabi-LMG)"
|
| 27 |
-
)
|
| 28 |
-
st.sidebar.write(
|
| 29 |
-
"Models source code available on [GitHub](https://github.com/boun-tabi-LMG/turkish-lm-tuner)"
|
| 30 |
-
)
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/Summarization.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import time
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="Text Summarization", page_icon="📈")
|
| 7 |
+
API_URL = "https://api-inference.huggingface.co/models/boun-tabi-LMG/turna_summarization_mlsum"
|
| 8 |
+
HF_AUTH_TOKEN = os.getenv('HF_AUTH_TOKEN')
|
| 9 |
+
headers = {"Authorization": f"Bearer {HF_AUTH_TOKEN}"}
|
| 10 |
+
|
| 11 |
+
st.markdown("# Text Summarization")
|
| 12 |
+
st.sidebar.header("Text Summarization")
|
| 13 |
+
st.write(
|
| 14 |
+
"""Here, you can summarize your text using the fine-tuned TURNA summarization models. """
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
input_text = st.text_area(label='Enter a text: ', height=200,
|
| 18 |
+
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. Pıhtılaşma ise vücudun bağışıklık tepkisinden kaynaklanan iltihaplanmayla birlikte damarlardaki yağlı plakları zayıflatabilir. Plağın yırtılmasıyla da kan pıhtısı oluşarak kalp krizine neden olabiliyor.")
|
| 19 |
+
if st.button("Generate"):
|
| 20 |
+
with st.spinner('Generating...'):
|
| 21 |
+
output = query(input_text)
|
| 22 |
+
st.success(output)
|
| 23 |
+
|
| 24 |
+
def query(payload):
|
| 25 |
+
#{"inputs": payload, ""}
|
| 26 |
+
while True:
|
| 27 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 28 |
+
if 'error' not in response.json():
|
| 29 |
+
output = response.json()[0]["generated_text"]
|
| 30 |
+
return output
|
| 31 |
+
else:
|
| 32 |
+
time.sleep(15)
|
| 33 |
+
print('Sending request again', flush=True)
|
| 34 |
+
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
awesome_streamlit
|
|
|
|
|
|
| 1 |
+
awesome_streamlit
|
| 2 |
+
transformers==4.37.1
|