3morrrrr commited on
Commit
09012d1
·
verified ·
1 Parent(s): b3a92e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -39
app.py CHANGED
@@ -1,41 +1,25 @@
1
- import threading
2
- import tarfile
3
- import os
4
- from flask import Flask, send_from_directory
5
- from rasa.core.agent import Agent
6
- from rasa.core.interpreter import RasaNLUInterpreter
7
- from rasa.utils.endpoints import EndpointConfig
8
- from rasa.core.channels.socketio import SocketIOInput
9
 
10
- # Define the paths
11
- model_tar_path = '20240510-131840-steel-limestone.tar.gz'
12
- extract_dir = 'extracted_model'
13
 
14
- # Extract the tar.gz file if not already extracted
15
- if not os.path.exists(extract_dir):
16
- os.makedirs(extract_dir, exist_ok=True)
17
- with tarfile.open(model_tar_path, 'r:gz') as tar:
18
- tar.extractall(path=extract_dir)
19
-
20
- # Load the Rasa agent
21
- model_path = os.path.join(extract_dir, 'models')
22
- agent = Agent.load(model_path)
23
-
24
- app = Flask(__name__, static_url_path='', static_folder='static')
25
-
26
- @app.route('/')
27
- def serve_index():
28
- return send_from_directory('static', 'chatwid.html')
29
-
30
- def run_rasa():
31
- input_channel = SocketIOInput(
32
- user_message_evt="user_uttered",
33
- bot_message_evt="bot_uttered",
34
- namespace=None
35
- )
36
- endpoint = EndpointConfig(url="http://localhost:5055/webhook")
37
- agent.handle_channels([input_channel], 5005, serve_forever=True)
38
-
39
- if __name__ == '__main__':
40
- threading.Thread(target=run_rasa).start()
41
- app.run(host='0.0.0.0', port=7860)
 
1
+ import streamlit as st
 
 
 
 
 
 
 
2
 
3
+ # Set the page title
4
+ st.set_page_config(page_title="Chatbot")
 
5
 
6
+ # Embed the HTML content
7
+ st.markdown("""
8
+ <!DOCTYPE html>
9
+ <html lang="en">
10
+ <body>
11
+ <script>
12
+ !(function () {
13
+ let e = document.createElement("script"),
14
+ t = document.head || document.getElementsByTagName("head")[0];
15
+ (e.src = "https://cdn.jsdelivr.net/npm/rasa-webchat@1.x.x/lib/index.js"),
16
+ // Replace 1.x.x with the version that you want
17
+ (e.async = !0),
18
+ (e.onload = () => {
19
+ window.WebChat.default(
20
+ {
21
+ initPayload: "/init_greet",
22
+ customData: { language: "en" },
23
+ socketUrl: "http://localhost:5005",
24
+ title: "Mybot",
25
+