Brian Morin
commited on
Commit
•
58802f0
1
Parent(s):
042b900
Add application file
Browse files
app.py
CHANGED
@@ -1,17 +1,43 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
# ran this on command line first in directory where I am putting app.py: git clone https://huggingface.co/spaces/brdemorin/chat
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
x = st.slider('Select a value')
|
6 |
st.write(x, 'squared is', x * x)
|
7 |
|
|
|
|
|
|
|
8 |
|
9 |
-
#
|
|
|
10 |
|
11 |
-
#
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
git push
|
17 |
-
"""
|
|
|
|
|
|
|
1 |
# ran this on command line first in directory where I am putting app.py: git clone https://huggingface.co/spaces/brdemorin/chat
|
2 |
+
# this will create a "chat" directory. This "app.py" file will need to be saved to that chat directory
|
3 |
+
# change directory in command line to: C:\Users\brian.morin\Documents\HuggingFace\chat
|
4 |
+
# then do the below. Must do the below everytime I make changes to app.py
|
5 |
+
|
6 |
+
"""
|
7 |
+
git add app.py
|
8 |
+
git commit -m "Add application file"
|
9 |
+
git push
|
10 |
+
"""
|
11 |
+
# I'm not sure if I actually need to do this: in your terminal, navigate to the directory containing your app.py file and run the command: streamlit run app.py
|
12 |
+
|
13 |
+
# then navigate here: https://huggingface.co/spaces/brdemorin/chat
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
import streamlit as st
|
23 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
24 |
|
25 |
x = st.slider('Select a value')
|
26 |
st.write(x, 'squared is', x * x)
|
27 |
|
28 |
+
# Load the tokenizer and model
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained("brdemorin/Phi3-custom_60-steps")
|
30 |
+
model = AutoModelForCausalLM.from_pretrained("brdemorin/Phi3-custom_60-steps")
|
31 |
|
32 |
+
# Create a text input for the user to enter their message
|
33 |
+
user_input = st.text_input("Enter your message:")
|
34 |
|
35 |
+
# When the user enters a message and presses enter, generate a response
|
36 |
+
if user_input:
|
37 |
+
# Encode the user's message and pass it to the model
|
38 |
+
input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors='pt')
|
39 |
+
generated_response_ids = model.generate(input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
40 |
|
41 |
+
# Decode the model's output IDs to a string and display it
|
42 |
+
generated_response = tokenizer.decode(generated_response_ids[:, input_ids.shape[-1]:][0], skip_special_tokens=True)
|
43 |
+
st.write(generated_response)
|
|
|
|