Creare app.py
Browse files
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
st.title("Meta LLaMA Text Generation")
|
5 |
+
|
6 |
+
@st.cache_resource
|
7 |
+
def load_model():
|
8 |
+
model_name = "meta-llama/Meta-Llama-3-8B"
|
9 |
+
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=access_token)
|
11 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=access_token)
|
12 |
+
return tokenizer, model
|
13 |
+
|
14 |
+
tokenizer, model = load_model()
|
15 |
+
|
16 |
+
prompt = st.text_input("Enter a prompt:", "Once upon a time")
|
17 |
+
|
18 |
+
if st.button("Generate Text"):
|
19 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
20 |
+
outputs = model.generate(**inputs, max_length=50)
|
21 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
22 |
+
st.write(generated_text)
|