jdidii commited on
Commit
9fe323f
1 Parent(s): f7cb446

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
3
+
4
+
5
+ model = T5ForConditionalGeneration.from_pretrained("t5-small")
6
+ tokenizer = T5Tokenizer.from_pretrained("t5-small")
7
+
8
+
9
+ def generate_response(input_text):
10
+ input_ids = tokenizer.encode("chatbot: " + input_text, return_tensors="pt", max_length=512)
11
+ output_ids = model.generate(input_ids, max_length=100, num_beams=1, early_stopping=True)
12
+ response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
13
+ return response
14
+
15
+ # Set up Streamlit app
16
+ st.title("Simple Chatbot with T5")
17
+ user_input = st.text_input("You:", "")
18
+
19
+ if st.button("Send"):
20
+ if user_input.strip() != "":
21
+ response = generate_response(user_input)
22
+ st.text_area("Bot:", response)
23
+ else:
24
+ st.warning("Please enter a valid input.")