mmaleki92 commited on
Commit
e509786
·
verified ·
1 Parent(s): 6f1d0a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -21
app.py CHANGED
@@ -1,35 +1,39 @@
1
  import streamlit as st
2
- from transformers import AutoModel, AutoTokenizer
3
- import torch
4
 
5
  # Title for your app
6
- st.title("Llama-3-8B-Physics Master - Model Inference")
7
 
8
- # Load the model and tokenizer from Hugging Face
9
  @st.cache_resource
10
  def load_model():
11
- model = AutoModel.from_pretrained("gallen881/Llama-3-8B-Physics_Master-GGUF")
12
- tokenizer = AutoTokenizer.from_pretrained("gallen881/Llama-3-8B-Physics_Master-GGUF")
13
- return model, tokenizer
 
 
 
14
 
15
  # Load the model once and store it in cache
16
- model, tokenizer = load_model()
17
 
18
  # Text input for the user
19
- user_input = st.text_area("Enter your input here:")
20
 
21
- if st.button("Generate Output"):
22
  if user_input:
23
- # Tokenize the input
24
- inputs = tokenizer(user_input, return_tensors="pt")
25
-
26
- # Forward pass through the model
27
- with torch.no_grad():
28
- outputs = model(**inputs)
29
-
30
- # Get the output embeddings or logits (depending on the model structure)
31
- # For example, let's say we want to display embeddings
32
- st.write("Model Output Embeddings:", outputs.last_hidden_state)
 
 
33
 
34
  else:
35
- st.write("Please enter some input.")
 
1
  import streamlit as st
2
+ from llama_cpp import Llama
 
3
 
4
  # Title for your app
5
+ st.title("Llama-3-8B-Physics Master - Chatbot")
6
 
7
+ # Load the model from Hugging Face using llama_cpp
8
  @st.cache_resource
9
  def load_model():
10
+ # Load the model from the Hugging Face Hub
11
+ model = Llama.from_pretrained(
12
+ repo_id="gallen881/Llama-3-8B-Physics_Master-GGUF",
13
+ filename="unsloth.F16.gguf" # or unsloth.Q4_K_M.gguf for a smaller file
14
+ )
15
+ return model
16
 
17
  # Load the model once and store it in cache
18
+ model = load_model()
19
 
20
  # Text input for the user
21
+ user_input = st.text_area("Enter your message here:")
22
 
23
+ if st.button("Generate Response"):
24
  if user_input:
25
+ # Create chat completion with the model
26
+ response = model.create_chat_completion(
27
+ messages=[
28
+ {
29
+ "role": "user",
30
+ "content": user_input
31
+ }
32
+ ]
33
+ )
34
+
35
+ # Extract the content from the model's response
36
+ st.write("Model Response:", response['choices'][0]['message']['content'])
37
 
38
  else:
39
+ st.write("Please enter a message.")