Lin Chen commited on
Commit
bd2b8d3
·
1 Parent(s): 2457ad3
Files changed (2) hide show
  1. app.py +26 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
3
+
4
+ # Load the Hugging Face API token from st.secrets
5
+ hf_api_token = st.secrets["HUGGINGFACE_API_TOKEN"]
6
+
7
+ # Load the model and tokenizer using the API token
8
+ model_name = "meta-llama/Meta-Llama-3.1-405B"
9
+ tokenizer = pipeline('text-generation', model_name, token=hf_api_token)
10
+
11
+ # Create a text generation pipeline
12
+ generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
13
+
14
+ # Streamlit UI
15
+ st.title("LLaMA 3.1-405B Model Text Generation")
16
+ st.write(hf_api_token)
17
+
18
+ # Input prompt
19
+ prompt = st.text_input("Enter your prompt:", value="Explain the significance of the theory of relativity.")
20
+
21
+ # Generate text on button click
22
+ if st.button("Generate Text"):
23
+ # Generate text using the pipeline
24
+ output = generator(prompt, max_length=100, num_return_sequences=1)
25
+ # Display the generated text
26
+ st.write(output[0]['generated_text'])
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ transformers
3
+ torch