Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,39 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
-
import torch
|
4 |
|
5 |
# Title for your app
|
6 |
-
st.title("Llama-3-8B-Physics Master -
|
7 |
|
8 |
-
# Load the model
|
9 |
@st.cache_resource
|
10 |
def load_model():
|
11 |
-
model
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
# Load the model once and store it in cache
|
16 |
-
model
|
17 |
|
18 |
# Text input for the user
|
19 |
-
user_input = st.text_area("Enter your
|
20 |
|
21 |
-
if st.button("Generate
|
22 |
if user_input:
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
33 |
|
34 |
else:
|
35 |
-
st.write("Please enter
|
|
|
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.")
|