Spaces:
Runtime error
Runtime error
Abinaya Mahendiran
commited on
Commit
·
2b02259
1
Parent(s):
36338f2
Updated app
Browse files- app.py +7 -9
- config.json +4 -1
app.py
CHANGED
@@ -5,8 +5,6 @@
|
|
5 |
# Install necessary libraries
|
6 |
from transformers import AutoTokenizer, AutoModelWithLMHead, pipeline
|
7 |
import streamlit as st
|
8 |
-
from pprint import pprint
|
9 |
-
import json
|
10 |
|
11 |
# Read the config
|
12 |
with open("config.json") as f:
|
@@ -29,22 +27,22 @@ def load_model(model_name):
|
|
29 |
return model, tokenizer
|
30 |
|
31 |
# Side bar
|
32 |
-
img = st.sidebar.image("images/tamil_logo.jpg", width=
|
33 |
|
34 |
# Choose the model based on selection
|
35 |
page = st.sidebar.selectbox("Model", config["models"])
|
36 |
data = st.sidebar.selectbox("Data", config[page])
|
37 |
|
38 |
# Main page
|
39 |
-
st.
|
40 |
st.markdown(
|
41 |
"This demo uses [GPT2 trained on Oscar dataset](https://huggingface.co/flax-community/gpt-2-tamil) "
|
42 |
"and [GPT2 trained on Oscar & Indic Corpus dataset] (https://huggingface.co/abinayam/gpt-2-tamil) "
|
43 |
-
"to show language generation"
|
44 |
)
|
45 |
|
46 |
if page == 'Text Generation' and data == 'Oscar':
|
47 |
-
st.
|
48 |
st.markdown('A simple demo using gpt-2-tamil model trained on Oscar data')
|
49 |
model, tokenizer = load_model(config[data])
|
50 |
# Set default options
|
@@ -56,12 +54,12 @@ if page == 'Text Generation' and data == 'Oscar':
|
|
56 |
try:
|
57 |
with st.spinner('Generating...'):
|
58 |
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
|
59 |
-
seqs = generator(seed, max_length=max_len)
|
60 |
st.write(seqs)
|
61 |
except Exception as e:
|
62 |
st.exception(f'Exception: {e}')
|
63 |
elif page == 'Text Generation' and data == "Oscar + Indic Corpus":
|
64 |
-
st.
|
65 |
st.markdown('A simple demo using gpt-2-tamil model trained on Oscar data')
|
66 |
model, tokenizer = load_model(config[data])
|
67 |
# Set default options
|
@@ -73,7 +71,7 @@ elif page == 'Text Generation' and data == "Oscar + Indic Corpus":
|
|
73 |
try:
|
74 |
with st.spinner('Generating...'):
|
75 |
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
|
76 |
-
seqs = generator(seed, max_length=max_len) #num_return_sequences=seq_num)
|
77 |
st.write(seqs)
|
78 |
except Exception as e:
|
79 |
st.exception(f'Exception: {e}')
|
|
|
5 |
# Install necessary libraries
|
6 |
from transformers import AutoTokenizer, AutoModelWithLMHead, pipeline
|
7 |
import streamlit as st
|
|
|
|
|
8 |
|
9 |
# Read the config
|
10 |
with open("config.json") as f:
|
|
|
27 |
return model, tokenizer
|
28 |
|
29 |
# Side bar
|
30 |
+
img = st.sidebar.image("images/tamil_logo.jpg", width=300)
|
31 |
|
32 |
# Choose the model based on selection
|
33 |
page = st.sidebar.selectbox("Model", config["models"])
|
34 |
data = st.sidebar.selectbox("Data", config[page])
|
35 |
|
36 |
# Main page
|
37 |
+
st.title("Tamil Language Demos")
|
38 |
st.markdown(
|
39 |
"This demo uses [GPT2 trained on Oscar dataset](https://huggingface.co/flax-community/gpt-2-tamil) "
|
40 |
"and [GPT2 trained on Oscar & Indic Corpus dataset] (https://huggingface.co/abinayam/gpt-2-tamil) "
|
41 |
+
"to show language generation!"
|
42 |
)
|
43 |
|
44 |
if page == 'Text Generation' and data == 'Oscar':
|
45 |
+
st.header('Tamil text generation with GPT2')
|
46 |
st.markdown('A simple demo using gpt-2-tamil model trained on Oscar data')
|
47 |
model, tokenizer = load_model(config[data])
|
48 |
# Set default options
|
|
|
54 |
try:
|
55 |
with st.spinner('Generating...'):
|
56 |
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
|
57 |
+
seqs = generator(seed, max_length=max_len)[0]['generated_text']# num_return_sequences=seq_num)
|
58 |
st.write(seqs)
|
59 |
except Exception as e:
|
60 |
st.exception(f'Exception: {e}')
|
61 |
elif page == 'Text Generation' and data == "Oscar + Indic Corpus":
|
62 |
+
st.header('Tamil text generation with GPT2')
|
63 |
st.markdown('A simple demo using gpt-2-tamil model trained on Oscar data')
|
64 |
model, tokenizer = load_model(config[data])
|
65 |
# Set default options
|
|
|
71 |
try:
|
72 |
with st.spinner('Generating...'):
|
73 |
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
|
74 |
+
seqs = generator(seed, max_length=max_len)[0]['generated_text'] #num_return_sequences=seq_num)
|
75 |
st.write(seqs)
|
76 |
except Exception as e:
|
77 |
st.exception(f'Exception: {e}')
|
config.json
CHANGED
@@ -3,5 +3,8 @@
|
|
3 |
"Text Generation": ["Oscar", "Oscar + Indic Corpus"],
|
4 |
"Text Classification": ["News Data"],
|
5 |
"Oscar": "flax-community/gpt-2-tamil",
|
6 |
-
"Oscar + Indic Corpus": "abinayam/gpt-2-tamil"
|
|
|
|
|
|
|
7 |
}
|
|
|
3 |
"Text Generation": ["Oscar", "Oscar + Indic Corpus"],
|
4 |
"Text Classification": ["News Data"],
|
5 |
"Oscar": "flax-community/gpt-2-tamil",
|
6 |
+
"Oscar + Indic Corpus": "abinayam/gpt-2-tamil",
|
7 |
+
"examples": ["ஒரு ஊரிலே ஒரு காக்கைக்கு",
|
8 |
+
"அன்பிர்க்கும் உன்டோ அடைக்கும்",
|
9 |
+
"தெனாலி ராமன், ஒரு பெரிய விகடகவி"]
|
10 |
}
|