File size: 2,212 Bytes
5dc09e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import awesome_streamlit as ast
import streamlit as st
from transformers import pipeline

import pages.turna

API_URL = "https://api-inference.huggingface.co/models/boun-tabi-LMG/TURNA"

st.set_page_config(
        page_title="Turna",
        page_icon="📖",
        layout='wide'
    )

st.markdown(
        """
        <h1 style="text-align:left;">TURNA</h1>
        """,
        unsafe_allow_html=True,
    )

    st.write("#")

    col = st.columns(2)

    col[0].image("images/turna-logo.png", width=100)

    st.markdown(
        """

        <h3 style="text-align:right;">TURNA is a Turkish encoder-decoder language model.</h3>
        
        <p style="text-align:right;"><p>
        <p style="text-align:right;">Use the generation paramters on the sidebar to adjust generation quality.</p>
        <p style="text-align:right;"><p>
        """,
        unsafe_allow_html=True,
    )

    #st.title('Turkish Language Generation')
    #st.write('...with Turna')
    input_text = st.text_area(label='Enter a text: ', height=100, 
        value="Türkiye'nin başkeni neresidir?")
    if st.button("Generate"):
        with st.spinner('Generating...'):
            output = query(input_text)
            st.success(output)

def query(payload):
    #{"inputs": payload, ""}
	while True:
		response = requests.post(API_URL, json=payload)
		if 'error' not in response.json():
			output = response.json()[0]["generated_text"]
			return output
		else:
			time.sleep(15)
			print('Sending request again', flush=True)

def pipe():
    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)

"""PAGES = {
    "Turkish Language Generation": pages.turna,
}

st.sidebar.title("Navigation")
selection = st.sidebar.radio("Pages", list(PAGES.keys()))

page = PAGES[selection]
# with st.spinner(f"Loading {selection} ..."):
ast.shared.components.write_page(page)"""

st.sidebar.header("Info")

st.sidebar.write(
    "Models are available on [HF Hub](https://huggingface.co/collections/boun-tabi-LMG)"
)
st.sidebar.write(
    "Model source code available on [GitHub](https://github.com/boun-tabi-LMG/turkish-lm-tuner)"
)