Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelWithLMHead, AutoTokenizer
|
3 |
+
|
4 |
+
# Title of the page
|
5 |
+
st.title("Text Generation with Huggingface Model")
|
6 |
+
|
7 |
+
# Tokenizer model selection
|
8 |
+
model_name = st.selectbox("Select a Huggingface model",
|
9 |
+
["distilbert-base-cased",
|
10 |
+
"gpt2",
|
11 |
+
"xlm-roberta-base"])
|
12 |
+
|
13 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
14 |
+
model = AutoModelWithLMHead.from_pretrained(model_name)
|
15 |
+
|
16 |
+
# Text box where the user can enter the text
|
17 |
+
text = st.text_area("Enter the text",
|
18 |
+
"Type your text here...")
|
19 |
+
|
20 |
+
# Generate the text
|
21 |
+
if st.button("Generate"):
|
22 |
+
input_ids = tokenizer.encode(text, return_tensors="pt")
|
23 |
+
output_ids = model.generate(input_ids)[0]
|
24 |
+
generated_text = tokenizer.decode(output_ids)
|
25 |
+
st.write(generated_text)
|