ZaryabKhan14 commited on
Commit
dc5fd84
1 Parent(s): dfdcaf0

Upload 3 files

Browse files
Files changed (3) hide show
  1. .env +1 -0
  2. app.py +48 -0
  3. requirements.txt +0 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ api_key=""
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import openai
3
+ import os
4
+ from dotenv import load_dotenv
5
+
6
+ # Load API key from .env file
7
+ load_dotenv()
8
+ api_key = os.getenv("api_key")
9
+
10
+ # Initialize OpenAI client
11
+ client = openai.Client(api_key=api_key)
12
+
13
+ def assistant_chatbot(user_query):
14
+ thread = client.beta.threads.create()
15
+
16
+ message = client.beta.threads.messages.create(
17
+ thread_id=thread.id,
18
+ role="user",
19
+ content=user_query,
20
+ )
21
+
22
+ run = client.beta.threads.runs.create(
23
+ thread_id=thread.id,
24
+ assistant_id="asst_6o7w7E8I6m0cVfM3zFzePcb9", # Replace with your assistant ID
25
+ instructions="Provide information related to health queries. Remember, this is not medical advice. For serious health concerns, consult a healthcare professional.",
26
+ )
27
+
28
+ # Wait for the run to complete
29
+ while not run.completed_at:
30
+ # Streamlit does not have a direct equivalent to time.sleep(), so we poll the run status
31
+ run = client.beta.threads.runs.retrieve(thread_id=thread.id, run_id=run.id)
32
+
33
+ messages = client.beta.threads.messages.list(thread_id=thread.id)
34
+ last_message = messages.data[0]
35
+ response = last_message.content[0].text.value
36
+ return response
37
+
38
+ # Streamlit app layout
39
+ st.title("Health Assistant Chatbot")
40
+
41
+ user_query = st.text_input("Enter your health query:")
42
+
43
+ if st.button("Submit"):
44
+ if user_query:
45
+ response = assistant_chatbot(user_query)
46
+ st.write(response)
47
+ else:
48
+ st.write("Please enter a query.")
requirements.txt ADDED
Binary file (2.1 kB). View file