Spaces:
Build error
Build error
Rename streamlit_app.py to app.py
Browse files- app.py +22 -0
- streamlit_app.py +0 -0
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 3 |
+
|
| 4 |
+
# Load custom trained model and tokenizer
|
| 5 |
+
model = GPT2LMHeadModel.from_pretrained('https://huggingface.co/spaces/SoniR/chatbotllm/blob/main/config.json')
|
| 6 |
+
tokenizer = GPT2Tokenizer.from_pretrained('https://huggingface.co/spaces/SoniR/chatbotllm/blob/main/pytorch_model.bin')
|
| 7 |
+
|
| 8 |
+
# Streamlit app title
|
| 9 |
+
st.title("Custom Trained Chatbot")
|
| 10 |
+
|
| 11 |
+
# Function to generate chatbot response
|
| 12 |
+
def generate_response(user_input):
|
| 13 |
+
input_ids = tokenizer.encode(user_input, return_tensors='pt')
|
| 14 |
+
output = model.generate(input_ids, max_length=50, num_return_sequences=1)
|
| 15 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 16 |
+
return response
|
| 17 |
+
|
| 18 |
+
# Main UI components
|
| 19 |
+
user_input = st.text_input("You:", key="user_input")
|
| 20 |
+
if st.button("Send"):
|
| 21 |
+
bot_response = generate_response(user_input)
|
| 22 |
+
st.write("Bot:", bot_response)
|
streamlit_app.py
DELETED
|
File without changes
|