Madhuri123 commited on
Commit
cb4d59e
·
verified ·
1 Parent(s): 3177be3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -1,20 +1,30 @@
1
  import streamlit as st
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
3
 
4
- # Load model and tokenizer
5
- model_name = "meta-llama/Meta-Llama-3-8B"
6
- tokenizer = AutoTokenizer.from_pretrained(model_name)
7
- model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
- def predict(input_text):
10
- inputs = tokenizer(input_text, return_tensors="pt")
11
- outputs = model.generate(**inputs)
12
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
 
 
 
13
 
14
- # Streamlit interface
15
  st.title("LLM Model Inference")
16
- input_text = st.text_area("Enter your text here:")
 
17
  if st.button("Generate"):
18
- output_text = predict(input_text)
19
- st.write(output_text)
 
 
 
 
 
 
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