InfoBetyar commited on
Commit
cdd855d
·
verified ·
1 Parent(s): 863c9d2

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +98 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # _____ _ _ _____ _____ _ _ _ _
2
+ # / ____| | | |_ _| / ____| | | | | | | |
3
+ # | | __| | | | | | | | | |__ __ _| |_| |__ ___ | |_
4
+ # | | |_ | | | | | | | | | '_ \ / _` | __| '_ \ / _ \| __|
5
+ # | |__| | |__| |_| |_ | |____| | | | (_| | |_| |_) | (_) | |_
6
+ # \_____|\____/|_____| \_____|_| |_|\__,_|\__|_.__/ \___/ \__|
7
+ #
8
+ # __________ ___ ___________ _____ ___
9
+ # / _/_ __/ / _ )/ __/_ __| \/ / _ | / _ \
10
+ # _/ / / / / _ / _/ / / \ / __ |/ , _/
11
+ # /___/ /_/ /____/___/ /_/ /_/_/ |_/_/|_|
12
+ #
13
+ # SOFT PILLOW VERZIÓ
14
+ # HF - Streamlit verzió
15
+
16
+
17
+ # streamlit run softpillow1.4streamlitchat.py
18
+
19
+ import streamlit as st
20
+ import time
21
+ from openai import OpenAI
22
+ from itb_kulcs import api_key
23
+ from itb_kulcs import assistant_id
24
+
25
+ client = OpenAI(api_key=api_key) # Init OpenAI client
26
+
27
+ ASSISTANT_ID = assistant_id # Assistant ID
28
+
29
+ st.title("IT Betyár - Custom-ChatBot") # Streamlit App Focim
30
+
31
+ # Initialize messages in session state if not present
32
+ if "messages" not in st.session_state:
33
+ st.session_state.messages = []
34
+
35
+ # Display existing messages
36
+ for message in st.session_state.messages:
37
+ with st.chat_message(message["role"]):
38
+ st.write(message["content"])
39
+
40
+ # Chat input
41
+ if prompt := st.chat_input("Type your message..."):
42
+ # Display user message
43
+ with st.chat_message("user"):
44
+ st.write(prompt)
45
+
46
+ # Add user message to state
47
+ st.session_state.messages.append({"role": "user", "content": prompt})
48
+
49
+ # Get assistant response
50
+ with st.chat_message("assistant"):
51
+ with st.spinner("Thinking..."):
52
+ # Create thread and send message
53
+ thread = client.beta.threads.create()
54
+ client.beta.threads.messages.create(
55
+ thread_id=thread.id,
56
+ role="user",
57
+ content=prompt
58
+ )
59
+
60
+ # Run assistant
61
+ run = client.beta.threads.runs.create(
62
+ thread_id=thread.id,
63
+ assistant_id=ASSISTANT_ID
64
+ )
65
+
66
+ # Wait for completion
67
+ while run.status != "completed":
68
+ time.sleep(0.5)
69
+ run = client.beta.threads.runs.retrieve(
70
+ thread_id=thread.id,
71
+ run_id=run.id
72
+ )
73
+
74
+ # Get and display response
75
+ messages = client.beta.threads.messages.list(thread_id=thread.id)
76
+ response = messages.data[0].content[0].text.value
77
+ cleaned_response = response.split("【")[0]
78
+ st.write(cleaned_response)
79
+
80
+ # Add assistant response to state
81
+ st.session_state.messages.append(
82
+ {"role": "assistant", "content": cleaned_response}
83
+ )
84
+
85
+ # Clean up thread
86
+ client.beta.threads.delete(thread.id)
87
+
88
+
89
+ # Teszt üzenetek:
90
+ #-------------------------------------
91
+ # What's the check in time?
92
+ # What are the check-in and check-out times?
93
+ # Are there any local restaurants you'd suggest?
94
+ # What's the Wi-Fi password for the property?
95
+ # What's the pin for the lockbox?
96
+ # What is the check-out procedure?
97
+ # What is the manager's name? --> NEM kell tudja!
98
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ openai