Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
|
| 4 |
-
# Choose an appropriate Hugging Face model for your chat application (replace with your desired model)
|
| 5 |
-
model_name = "facebook/bart-base"
|
| 6 |
-
|
| 7 |
-
# Initialize the conversational AI pipeline
|
| 8 |
-
chat_pipeline = pipeline("conversational", model=model_name)
|
| 9 |
-
|
| 10 |
-
# Initialize session state to store chat history
|
| 11 |
-
if "chat_history" not in st.session_state:
|
| 12 |
-
st.session_state["chat_history"] = []
|
| 13 |
-
|
| 14 |
-
def display_chat_history():
|
| 15 |
-
"""Displays the chat history in the Streamlit app."""
|
| 16 |
-
for message in st.session_state["chat_history"]:
|
| 17 |
-
st.write(f"{message['user']}: {message['text']}")
|
| 18 |
-
|
| 19 |
-
def process_user_input(user_input):
|
| 20 |
-
"""Processes user input using the conversational AI model and updates chat history."""
|
| 21 |
-
if user_input:
|
| 22 |
-
bot_response = chat_pipeline(user_input, max_length=1000)[0]["generated_text"]
|
| 23 |
-
st.session_state["chat_history"].append({"user": "You", "text": user_input})
|
| 24 |
-
st.session_state["chat_history"].append({"user": "Bot", "text": bot_response})
|
| 25 |
-
|
| 26 |
-
st.title("Streamlit Chat App with Hugging Face Model")
|
| 27 |
-
|
| 28 |
-
# Display chat history
|
| 29 |
-
display_chat_history()
|
| 30 |
-
|
| 31 |
-
# User input using st.chat_input
|
| 32 |
-
user_input = st.chat_input("Type your message here...", key="user_input")
|
| 33 |
-
|
| 34 |
-
# Process user input on Enter key press
|
| 35 |
-
if st.session_state.get("user_input", "") != user_input:
|
| 36 |
-
process_user_input(user_input)
|
| 37 |
-
st.session_state["user_input"] = "" # Clear input field
|
| 38 |
-
|
| 39 |
-
st.write("**Note:** This is a simple demonstration. For more advanced features, consider using a dedicated chatbot framework.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|