Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
model_name = "norman-codes/transfer-learning-attempt1"
|
| 5 |
+
|
| 6 |
+
# Load the model and tokenizer from Hugging Face Hub
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 9 |
+
|
| 10 |
+
st.title("Text Generation with GPT-Neo")
|
| 11 |
+
st.write("This is a text generation model running on Hugging Face Spaces. Enter a prompt to generate text.")
|
| 12 |
+
|
| 13 |
+
prompt = st.text_input("Enter your prompt here:")
|
| 14 |
+
|
| 15 |
+
if st.button("Generate Text"):
|
| 16 |
+
with st.spinner("Generating..."):
|
| 17 |
+
# Encode the input prompt and generate text
|
| 18 |
+
input_ids = tokenizer(prompt, return_tensors="pt", add_special_tokens=True).input_ids
|
| 19 |
+
generated_ids = model.generate(input_ids, max_length=100)
|
| 20 |
+
generated_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
| 21 |
+
|
| 22 |
+
st.text_area("Generated Text:", value=generated_text, height=200, max_chars=None, key=None)
|