Spaces:
Sleeping
Sleeping
Ray Leung
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Set up the Streamlit app
|
| 5 |
+
st.title("Simple Chatbot")
|
| 6 |
+
|
| 7 |
+
# Initialize the Hugging Face pipeline for conversation
|
| 8 |
+
chatbot = pipeline("conversational", model="facebook/blenderbot-400M-distill")
|
| 9 |
+
|
| 10 |
+
# Function to handle user input and bot response
|
| 11 |
+
def get_response(user_input):
|
| 12 |
+
conversation = chatbot(user_input)
|
| 13 |
+
response = conversation[0]['generated_text']
|
| 14 |
+
return response
|
| 15 |
+
|
| 16 |
+
# Text input for user
|
| 17 |
+
user_input = st.text_input("You: ", "")
|
| 18 |
+
|
| 19 |
+
# When the user enters text
|
| 20 |
+
if user_input:
|
| 21 |
+
response = get_response(user_input)
|
| 22 |
+
st.write(f"Bot: {response}")
|