Spaces:
Runtime error
Runtime error
adding a basic working demo for sinhala GPT2
Browse files- README.md +4 -4
- app.py +28 -0
- requirements.txt +5 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: streamlit
|
7 |
app_file: app.py
|
8 |
pinned: false
|
|
|
1 |
---
|
2 |
+
title: SinhalaGPT2
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: green
|
6 |
sdk: streamlit
|
7 |
app_file: app.py
|
8 |
pinned: false
|
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
3 |
+
|
4 |
+
st.title('Sinhala Text generation with GPT2')
|
5 |
+
st.markdown('A simple demo using Sinhala-gpt2 model trained during hf-flax week')
|
6 |
+
|
7 |
+
seed = st.text_input('Starting text', 'ආයුබෝවන්')
|
8 |
+
seq_num = st.number_input('Number of sentences to generate ', 1, 20, 5)
|
9 |
+
max_len = st.number_input('Length of the sentence ', 5, 300, 100)
|
10 |
+
|
11 |
+
go = st.button('Generate')
|
12 |
+
|
13 |
+
st.write('Waiting for the model to load.....')
|
14 |
+
model = AutoModelForCausalLM.from_pretrained('flax-community/Sinhala-gpt2')
|
15 |
+
tokenizer = AutoTokenizer.from_pretrained('flax-community/Sinhala-gpt2')
|
16 |
+
st.write('Model loaded!!')
|
17 |
+
|
18 |
+
if go:
|
19 |
+
try:
|
20 |
+
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
|
21 |
+
seqs = generator(seed, max_length=max_len, num_return_sequences=seq_num)
|
22 |
+
st.write(seqs)
|
23 |
+
except Exception as e:
|
24 |
+
st.exception(f'Exception: {e}')
|
25 |
+
|
26 |
+
st.markdown('____________')
|
27 |
+
st.markdown('by Keshan with Flax Community')
|
28 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
streamlit
|
3 |
+
jax
|
4 |
+
torch
|
5 |
+
flax
|