Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,30 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
-
# Streamlit interface
|
15 |
st.title("LLM Model Inference")
|
16 |
-
input_text = st.
|
|
|
17 |
if st.button("Generate"):
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
1 |
import streamlit as st
|
2 |
+
import transformers
|
3 |
+
import torch
|
4 |
|
5 |
+
HF_TOKEN=st.secrets(["HF_Token"])
|
6 |
+
# Load the model and pipeline
|
7 |
+
model_id = "meta-llama/Meta-Llama-3-8B"
|
|
|
8 |
|
9 |
+
# Set up the pipeline with the Hugging Face token
|
10 |
+
pipeline = transformers.pipeline(
|
11 |
+
"text-generation",
|
12 |
+
model=model_id,
|
13 |
+
model_kwargs={"torch_dtype": torch.bfloat16, "use_auth_token": HF_TOKEN}, # Pass the token here
|
14 |
+
device_map="auto"
|
15 |
+
)
|
16 |
|
17 |
+
# Streamlit user interface
|
18 |
st.title("LLM Model Inference")
|
19 |
+
input_text = st.text_input("Enter your prompt:")
|
20 |
+
|
21 |
if st.button("Generate"):
|
22 |
+
if input_text: # Check if the input is not empty
|
23 |
+
# Generate text using the pipeline
|
24 |
+
response = pipeline(input_text, max_length=150, num_return_sequences=1) # Customize as needed
|
25 |
+
st.write("Generated Response:")
|
26 |
+
st.write(response[0]['generated_text']) # Display the generated text
|
27 |
+
else:
|
28 |
+
st.error("Please enter a prompt to generate text.")
|
29 |
+
|
30 |
|