Spaces:
Sleeping
Sleeping
Keira James
commited on
Commit
·
be10833
1
Parent(s):
99256f5
switch to gpt2
Browse files
app.py
CHANGED
@@ -1,12 +1,28 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Title of the app
|
4 |
-
st.title("
|
|
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
# Display the input text
|
10 |
if user_input:
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
|
4 |
+
# Load pre-trained model and tokenizer from Hugging Face
|
5 |
+
model_name = "gpt2" # You can use other models like "gpt-neo", "gpt-3", etc.
|
6 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
# Title of the app
|
10 |
+
st.title("LLM Chatbot")
|
11 |
+
|
12 |
+
# User input for chatbot
|
13 |
+
user_input = st.text_input("You: ", "")
|
14 |
|
15 |
+
# Function to generate the response using the model
|
16 |
+
def generate_response(prompt):
|
17 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
18 |
+
outputs = model.generate(inputs.input_ids, max_length=150, num_return_sequences=1)
|
19 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
20 |
+
return response
|
21 |
|
|
|
22 |
if user_input:
|
23 |
+
# Generate a response from the model
|
24 |
+
response = generate_response(user_input)
|
25 |
+
|
26 |
+
# Display only the bot's response
|
27 |
+
st.write(f"Bot: {response}")
|
28 |
|