File size: 1,265 Bytes
40e9898
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6ec60b9
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
""" Script for streamlit demo
    @author: AbinayaM02
"""

# Install necessary libraries
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
import streamlit as st
from pprint import pprint
import json

# Read the config
with open("config.json") as f:
    cfg = json.loads(f.read())

# Set page layout
st.set_page_config(layout="wide")

# Load the model
@st.cache(allow_output_mutation=True)
def load_model():
    tokenizer = AutoTokenizer.from_pretrained(cfg["model_name_or_path"])
    model = AutoModelForCausalLM.from_pretrained(cfg["model_name_or_path"])
    generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
    return generator, tokenizer

with st.spinner('Loading model...'):
    generator, tokenizer = load_model()

# st.image("images/chef-transformer.png", width=400)
st.header("Tamil Language Demos")
st.markdown(
    "This demo uses [GPT2 trained on Oscar dataset](https://huggingface.co/flax-community/gpt-2-tamil) "
    "to show language generation and other downstream tasks"
)
img = st.sidebar.image("images/tamil_logo.png", width=100)
add_text_sidebar = st.sidebar.title("Select demo:")
sampling_mode = st.sidebar.selectbox("select a demo", index=0, options=["Text Generation", "Text Classification"])