Spaces:
Runtime error
Runtime error
MudassirFayaz
commited on
Commit
•
f4cb21e
1
Parent(s):
6f56570
added folders
Browse files
app.py
CHANGED
@@ -1,24 +1,29 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
|
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
def
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
|
13 |
# Streamlit app
|
14 |
-
st.title("
|
15 |
-
st.write("
|
16 |
|
17 |
-
|
18 |
-
user_input = st.text_area("Enter your prompt here:", "The answer to the universe is")
|
19 |
|
20 |
-
if st.button("
|
21 |
-
|
22 |
-
|
23 |
-
st.
|
24 |
-
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
+
import torch
|
4 |
|
5 |
+
# Load the tokenizer and model
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained('tokenizer-llama_career_0.5.0')
|
7 |
+
model = AutoModelForCausalLM.from_pretrained('llama-2-7b-career-0.5.0',
|
8 |
+
adapter_name_or_path='path/to/model/folder/adapter_model.bin')
|
9 |
|
10 |
+
# Function to generate response
|
11 |
+
def generate_response(input_text):
|
12 |
+
inputs = tokenizer(input_text, return_tensors='pt')
|
13 |
+
with torch.no_grad():
|
14 |
+
outputs = model.generate(**inputs, max_length=50, do_sample=True)
|
15 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
16 |
+
return response
|
17 |
|
18 |
# Streamlit app
|
19 |
+
st.title("Hugging Face Model Chatbot")
|
20 |
+
st.write("Interact with your custom model")
|
21 |
|
22 |
+
input_text = st.text_input("You:", "")
|
|
|
23 |
|
24 |
+
if st.button("Generate Response"):
|
25 |
+
if input_text:
|
26 |
+
response = generate_response(input_text)
|
27 |
+
st.write(f"Model: {response}")
|
28 |
+
else:
|
29 |
+
st.write("Please enter some text.")
|