Spaces:
Runtime error
Runtime error
pvanand
commited on
Commit
•
c847e76
0
Parent(s):
Duplicate from pvanand/RASA-chat-interface-2-Collaborator-Career-paths
Browse files- .gitattributes +35 -0
- Api_how_to.ipynb +66 -0
- Dockerfile +45 -0
- README.md +11 -0
- app.py +62 -0
- requirements.txt +1 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Api_how_to.ipynb
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "aab24c61",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"import requests\n",
|
11 |
+
"import json"
|
12 |
+
]
|
13 |
+
},
|
14 |
+
{
|
15 |
+
"cell_type": "code",
|
16 |
+
"execution_count": 6,
|
17 |
+
"id": "df363313",
|
18 |
+
"metadata": {},
|
19 |
+
"outputs": [
|
20 |
+
{
|
21 |
+
"name": "stdout",
|
22 |
+
"output_type": "stream",
|
23 |
+
"text": [
|
24 |
+
"[{'recipient_id': 'user', 'text': 'Hey! How are you?'}]\n"
|
25 |
+
]
|
26 |
+
}
|
27 |
+
],
|
28 |
+
"source": [
|
29 |
+
"user_input = \"Hi\"\n",
|
30 |
+
"payload = {\"sender\": \"user\", \"message\": user_input}\n",
|
31 |
+
"response = requests.post('http://localhost:5005/webhooks/rest/webhook', json=payload)\n",
|
32 |
+
"bot_reply = response.json()\n",
|
33 |
+
"print(bot_reply)"
|
34 |
+
]
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"cell_type": "code",
|
38 |
+
"execution_count": null,
|
39 |
+
"id": "9177e987",
|
40 |
+
"metadata": {},
|
41 |
+
"outputs": [],
|
42 |
+
"source": []
|
43 |
+
}
|
44 |
+
],
|
45 |
+
"metadata": {
|
46 |
+
"kernelspec": {
|
47 |
+
"display_name": "Python 3 (ipykernel)",
|
48 |
+
"language": "python",
|
49 |
+
"name": "python3"
|
50 |
+
},
|
51 |
+
"language_info": {
|
52 |
+
"codemirror_mode": {
|
53 |
+
"name": "ipython",
|
54 |
+
"version": 3
|
55 |
+
},
|
56 |
+
"file_extension": ".py",
|
57 |
+
"mimetype": "text/x-python",
|
58 |
+
"name": "python",
|
59 |
+
"nbconvert_exporter": "python",
|
60 |
+
"pygments_lexer": "ipython3",
|
61 |
+
"version": "3.10.11"
|
62 |
+
}
|
63 |
+
},
|
64 |
+
"nbformat": 4,
|
65 |
+
"nbformat_minor": 5
|
66 |
+
}
|
Dockerfile
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# syntax=docker/dockerfile:1
|
2 |
+
|
3 |
+
# Comments are provided throughout this file to help you get started.
|
4 |
+
# If you need more help, visit the Dockerfile reference guide at
|
5 |
+
# https://docs.docker.com/engine/reference/builder/
|
6 |
+
|
7 |
+
ARG PYTHON_VERSION=3.9
|
8 |
+
FROM python:${PYTHON_VERSION}-slim as base
|
9 |
+
|
10 |
+
RUN apt-get update && apt-get install -y \
|
11 |
+
build-essential \
|
12 |
+
curl \
|
13 |
+
software-properties-common \
|
14 |
+
git \
|
15 |
+
&& rm -rf /var/lib/apt/lists/*
|
16 |
+
|
17 |
+
# Copy the requirements file into the container.
|
18 |
+
COPY requirements.txt .
|
19 |
+
|
20 |
+
# Install the dependencies from the requirements file.
|
21 |
+
RUN pip3 install --no-cache-dir -r requirements.txt
|
22 |
+
|
23 |
+
# Prevents Python from writing pyc files.
|
24 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
25 |
+
|
26 |
+
# Keeps Python from buffering stdout and stderr to avoid situations where
|
27 |
+
# the application crashes without emitting any logs due to buffering.
|
28 |
+
ENV PYTHONUNBUFFERED=1
|
29 |
+
|
30 |
+
WORKDIR /app
|
31 |
+
# Copy the source code into the container.
|
32 |
+
COPY . .
|
33 |
+
|
34 |
+
# Create a non-privileged user that the app will run under.
|
35 |
+
# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
|
36 |
+
# Switch to the non-privileged user to run the application.
|
37 |
+
USER 1001
|
38 |
+
|
39 |
+
# Expose the port that the application listens on.
|
40 |
+
EXPOSE 7860
|
41 |
+
|
42 |
+
HEALTHCHECK CMD curl --fail http://localhost:7860/_stcore/health
|
43 |
+
|
44 |
+
# set entrypoint for interactive shells
|
45 |
+
ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|
README.md
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: RASA-chat-interface-2-Collaborator-Career-paths
|
3 |
+
emoji: 🐢
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
duplicated_from: pvanand/RASA-chat-interface-2-Collaborator-Career-paths
|
9 |
+
---
|
10 |
+
|
11 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import streamlit as st
|
3 |
+
import time
|
4 |
+
|
5 |
+
st.title("Rasa Chatbot Interface")
|
6 |
+
|
7 |
+
# Edit API url here
|
8 |
+
url = 'https://pvanand-rasa-omdena-collaborator-career-path.hf.space'
|
9 |
+
|
10 |
+
# Initialize chat history
|
11 |
+
if "messages" not in st.session_state:
|
12 |
+
st.session_state.messages = []
|
13 |
+
|
14 |
+
# Display chat messages from history on app rerun
|
15 |
+
for message in st.session_state.messages:
|
16 |
+
with st.chat_message(message["role"]):
|
17 |
+
st.markdown(message["content"])
|
18 |
+
|
19 |
+
# Accept user input
|
20 |
+
if user_input := st.chat_input("What is up?"):
|
21 |
+
# Add user message to chat history
|
22 |
+
st.session_state.messages.append({"role": "user", "content": user_input})
|
23 |
+
# Display user message in chat message container
|
24 |
+
with st.chat_message("user"):
|
25 |
+
st.markdown(user_input)
|
26 |
+
|
27 |
+
# Send user input to Rasa webhook
|
28 |
+
payload = {"sender": "user", "message": user_input}
|
29 |
+
response = requests.post(url+'/webhooks/rest/webhook', json=payload)
|
30 |
+
bot_reply = response.json()
|
31 |
+
|
32 |
+
# Extract assistant response
|
33 |
+
if bot_reply !=[]:
|
34 |
+
assistant_response = bot_reply[0]["text"]
|
35 |
+
else:
|
36 |
+
assistant_response = 'API request returned with an empty list []. Please continue with a different question'
|
37 |
+
|
38 |
+
# Display assistant response in chat message container
|
39 |
+
with st.chat_message("assistant"):
|
40 |
+
message_placeholder = st.empty()
|
41 |
+
full_response = ""
|
42 |
+
# Simulate stream of response with milliseconds delay
|
43 |
+
for chunk in assistant_response.split():
|
44 |
+
full_response += chunk + " "
|
45 |
+
time.sleep(0.05)
|
46 |
+
# Add a blinking cursor to simulate typing
|
47 |
+
message_placeholder.markdown(full_response + "▌")
|
48 |
+
message_placeholder.markdown(full_response)
|
49 |
+
|
50 |
+
# Add assistant response to chat history
|
51 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
52 |
+
|
53 |
+
# Add debug button to display RASA version, Model Name
|
54 |
+
with st.expander("Debug"):
|
55 |
+
if st.button("Show Debug Info"):
|
56 |
+
request_ids = ['/status', '/version']
|
57 |
+
results = [requests.get(url+request_id).json() for request_id in request_ids]
|
58 |
+
st.write(results)
|
59 |
+
else:
|
60 |
+
st.write("")
|
61 |
+
|
62 |
+
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
streamlit
|