Spaces:
Sleeping
Sleeping
Initial App Commit
Browse files
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
# Load environment variables from .env file
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Set the OpenAI API key from the environment variables
|
10 |
+
openai.api_key = os.getenv("API_KEY")
|
11 |
+
|
12 |
+
# Define a dictionary to store the conversation history for each session
|
13 |
+
conversation_histories = {}
|
14 |
+
|
15 |
+
# Streamlit app definition
|
16 |
+
def main():
|
17 |
+
st.title("Tech Support Chatbot")
|
18 |
+
|
19 |
+
# Initialize or continue the session's conversation history
|
20 |
+
if 'history' not in st.session_state:
|
21 |
+
st.session_state.history = []
|
22 |
+
|
23 |
+
user_input = st.text_input("Your question:", key="user_input")
|
24 |
+
|
25 |
+
if st.button("Send"):
|
26 |
+
response = get_message(user_input)
|
27 |
+
st.session_state.history.append(f"User: {user_input}")
|
28 |
+
st.session_state.history.append(f"Chatbot: {response}")
|
29 |
+
st.write(f"Chatbot: {response}")
|
30 |
+
|
31 |
+
def get_message(user_input):
|
32 |
+
context = """
|
33 |
+
You are an IT Support chatbot specialized in tech support for our company ACME INC Please do not ask for screenshots or images.
|
34 |
+
You should be proficient in diagnosing and troubleshooting software issues, hardware issues, and issues with peripheral devices.
|
35 |
+
If you think that a reboot/restart is needed, please explain clearly how this can help fix the user issue in detail.
|
36 |
+
You should also be capable of addressing network connectivity issues, providing guidance on security and privacy features,
|
37 |
+
helping with data management and navigating through system settings for application permissions and software updates.
|
38 |
+
Additionally, you have knowledge about commonly used productivity applications and tools that may help users in their daily tasks.
|
39 |
+
Please keep the conversation focused soley around IT Support.
|
40 |
+
"""
|
41 |
+
|
42 |
+
conversation_history = st.session_state.history
|
43 |
+
conversation_history_with_context = [context] + conversation_history
|
44 |
+
|
45 |
+
response = openai.Completion.create(
|
46 |
+
engine="text-davinci-003",
|
47 |
+
prompt="\n".join(conversation_history_with_context) + "\nChatbot:",
|
48 |
+
temperature=0,
|
49 |
+
max_tokens=150,
|
50 |
+
top_p=1,
|
51 |
+
frequency_penalty=0,
|
52 |
+
presence_penalty=0,
|
53 |
+
stop=["\n"],
|
54 |
+
)
|
55 |
+
|
56 |
+
return response.choices[0].text.strip()
|
57 |
+
|
58 |
+
if __name__ == "__main__":
|
59 |
+
main()
|