Spaces:
Runtime error
Runtime error
Abinaya Mahendiran
commited on
Commit
·
40e9898
1
Parent(s):
6f87c42
Initial demo
Browse files- app.py +38 -0
- config.json +5 -0
- images/tamil_logo.png +0 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" Script for streamlit demo
|
| 2 |
+
@author: AbinayaM02
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
# Install necessary libraries
|
| 6 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
| 7 |
+
import streamlit as st
|
| 8 |
+
#from streamlit_tags import st_tags
|
| 9 |
+
from pprint import pprint
|
| 10 |
+
import json
|
| 11 |
+
|
| 12 |
+
# Read the config
|
| 13 |
+
with open("config.json") as f:
|
| 14 |
+
cfg = json.loads(f.read())
|
| 15 |
+
|
| 16 |
+
# Set page layout
|
| 17 |
+
st.set_page_config(layout="wide")
|
| 18 |
+
|
| 19 |
+
# Load the model
|
| 20 |
+
@st.cache(allow_output_mutation=True)
|
| 21 |
+
def load_model():
|
| 22 |
+
tokenizer = AutoTokenizer.from_pretrained(cfg["model_name_or_path"])
|
| 23 |
+
model = AutoModelForCausalLM.from_pretrained(cfg["model_name_or_path"])
|
| 24 |
+
generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
| 25 |
+
return generator, tokenizer
|
| 26 |
+
|
| 27 |
+
with st.spinner('Loading model...'):
|
| 28 |
+
generator, tokenizer = load_model()
|
| 29 |
+
|
| 30 |
+
# st.image("images/chef-transformer.png", width=400)
|
| 31 |
+
st.header("Tamil Language Demos")
|
| 32 |
+
st.markdown(
|
| 33 |
+
"This demo uses [GPT2 trained on Oscar dataset](https://huggingface.co/flax-community/gpt-2-tamil) "
|
| 34 |
+
"to show language generation and other downstream tasks"
|
| 35 |
+
)
|
| 36 |
+
img = st.sidebar.image("images/tamil_logo.png", width=100)
|
| 37 |
+
add_text_sidebar = st.sidebar.title("Select demo:")
|
| 38 |
+
sampling_mode = st.sidebar.selectbox("select a Mode", index=0, options=["Top Sampling", "Beam Search"])
|
config.json
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_name_or_path": "flax-community/gpt-2-tamil/gpt-2-tamil",
|
| 3 |
+
"Text Generation": ["example_1", "example_2"],
|
| 4 |
+
"Text Classification": ["example_2", "example_2"]
|
| 5 |
+
}
|
images/tamil_logo.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
transformers
|