Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_model():
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B")
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B")
|
| 9 |
+
return pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 10 |
+
|
| 11 |
+
# Load the text generation pipeline
|
| 12 |
+
text_gen_pipeline = load_model()
|
| 13 |
+
|
| 14 |
+
# Streamlit app interface
|
| 15 |
+
st.title("Text Generation with Meta-Llama-3-8B")
|
| 16 |
+
st.write("Enter some text and click the button to generate a continuation.")
|
| 17 |
+
|
| 18 |
+
# User input
|
| 19 |
+
user_input = st.text_area("Input Text", "Once upon a time")
|
| 20 |
+
|
| 21 |
+
# Generate text on button click
|
| 22 |
+
if st.button("Generate Text"):
|
| 23 |
+
with st.spinner("Generating..."):
|
| 24 |
+
generated_text = text_gen_pipeline(user_input, max_length=100, num_return_sequences=1)
|
| 25 |
+
st.write(generated_text[0]['generated_text'])
|
| 26 |
+
|