Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +27 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,29 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
""
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the Hugging Face pipeline
|
| 5 |
+
chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium")
|
| 6 |
+
|
| 7 |
+
st.set_page_config(page_title="Chatbot", layout="centered")
|
| 8 |
+
|
| 9 |
+
st.title("🤖 Simple Chatbot")
|
| 10 |
+
|
| 11 |
+
# Initialize chat history
|
| 12 |
+
if "chat_history" not in st.session_state:
|
| 13 |
+
st.session_state.chat_history = []
|
| 14 |
+
|
| 15 |
+
# Input box
|
| 16 |
+
user_input = st.text_input("You:", key="input")
|
| 17 |
+
|
| 18 |
+
if user_input:
|
| 19 |
+
from transformers import Conversation
|
| 20 |
+
conversation = Conversation(user_input)
|
| 21 |
+
result = chatbot(conversation)
|
| 22 |
+
|
| 23 |
+
response = result.generated_responses[-1]
|
| 24 |
+
st.session_state.chat_history.append(("You", user_input))
|
| 25 |
+
st.session_state.chat_history.append(("Bot", response))
|
| 26 |
+
|
| 27 |
+
# Display chat history
|
| 28 |
+
for speaker, text in st.session_state.chat_history:
|
| 29 |
+
st.write(f"**{speaker}:** {text}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|