Spaces:
Runtime error
Runtime error
alirani
commited on
Commit
•
233c774
1
Parent(s):
6b329ae
afeat: ddd requirements.txt + model to app
Browse files- app.py +22 -3
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,13 +1,32 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
favicon = "https://i.ibb.co/JRdhFZg/favicon-32x32.png"
|
4 |
|
5 |
-
st.set_page_config(page_title=
|
6 |
|
7 |
st.title('Demo LoreFinder')
|
8 |
|
9 |
st.header('Generate a story')
|
10 |
|
11 |
-
st.text_input('Type a title to generate a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
st.button('Get synopsis')
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, TFAutoModelForCausalLM
|
3 |
+
|
4 |
+
# MODEL TO CALL
|
5 |
+
|
6 |
+
model_name = "Alirani/distilgpt2-finetuned-synopsis"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = TFAutoModelForCausalLM.from_pretrained(model_name)
|
9 |
+
|
10 |
+
def generate_synopsis(model, tokenizer, title):
|
11 |
+
input_ids = tokenizer(title, return_tensors="tf")
|
12 |
+
output = model.generate(input_ids['input_ids'], max_length=150, num_beams=5, no_repeat_ngram_size=2, top_k=50, attention_mask=input_ids['attention_mask'])
|
13 |
+
synopsis = tokenizer.decode(output[0], skip_special_tokens=True)
|
14 |
+
return synopsis
|
15 |
|
16 |
favicon = "https://i.ibb.co/JRdhFZg/favicon-32x32.png"
|
17 |
|
18 |
+
st.set_page_config(page_title="LoreFinder-demo", page_icon = favicon, layout = 'wide', initial_sidebar_state = 'auto')
|
19 |
|
20 |
st.title('Demo LoreFinder')
|
21 |
|
22 |
st.header('Generate a story')
|
23 |
|
24 |
+
prod_title = st.text_input('Type a title to generate a synopsis')
|
25 |
+
|
26 |
+
st.button('Get synopsis')
|
27 |
+
|
28 |
+
if prod_title:
|
29 |
+
gen_synopsis = generate_synopsis(model, tokenizer, prod_title)
|
30 |
+
st.text_area(gen_synopsis, disabled=True)
|
31 |
+
|
32 |
|
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
transformers
|