Anne31415 commited on
Commit
c011b95
·
1 Parent(s): 01afc48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -29
app.py CHANGED
@@ -27,10 +27,6 @@ def handle_and_display_image(file_id):
27
  print('Failed to download file.')
28
  return None
29
 
30
-
31
- if "api_call_status" not in st.session_state:
32
- st.session_state.api_call_status = None
33
-
34
  # Initialize global session state
35
  if "session_id" not in st.session_state:
36
  st.session_state.session_id = str(uuid.uuid4())
@@ -95,32 +91,16 @@ def page1():
95
  st.title("Assitent-Name")
96
  st.text("Beschreibung")
97
 
98
-
99
- if "assistant" not in st.session_state:
100
  openai.api_key = api_key
 
101
  st.session_state.assistant = openai.beta.assistants.retrieve(assistant_id)
102
- st.session_state.thread = client.beta.threads.create(metadata={'session_id': st.session_state.session_id})
103
-
104
- # User input
105
- prompt = st.text_input("Wie kann ich dir helfen?")
106
-
107
- # Submit button
108
- if st.button("Submit"):
109
- st.session_state.api_call_status = "pending"
110
- # Here, use the prompt to make your API call
111
- # For example, adding the prompt to the thread and creating a run
112
- response = "This is a simulated response" # Replace with actual response
113
- st.session_state.messages.append(("User", prompt))
114
- st.session_state.messages.append(("Assistant", response))
115
- st.session_state.api_call_status = "completed"
116
-
117
-
118
- # Display messages
119
- for role, message in st.session_state.messages:
120
- st.text(f"{role}: {message}")
121
 
 
 
 
 
122
 
123
-
124
  # If the run is completed, display the messages
125
  elif hasattr(st.session_state.run, 'status') and st.session_state.run.status == "completed":
126
  # Retrieve the list of messages
@@ -144,9 +124,8 @@ def page1():
144
 
145
 
146
 
147
- # Display chat history
148
- for sender, message in st.session_state.chat_history:
149
- st.text(f"{sender}: {message}")
150
 
151
 
152
  # Add message to the thread
 
27
  print('Failed to download file.')
28
  return None
29
 
 
 
 
 
30
  # Initialize global session state
31
  if "session_id" not in st.session_state:
32
  st.session_state.session_id = str(uuid.uuid4())
 
91
  st.title("Assitent-Name")
92
  st.text("Beschreibung")
93
 
94
+ if "assistant" not in st.session_state:
 
95
  openai.api_key = api_key
96
+ # Load the previously created assistant
97
  st.session_state.assistant = openai.beta.assistants.retrieve(assistant_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
+ # Create a new thread for this session
100
+ st.session_state.thread = client.beta.threads.create(
101
+ metadata={'session_id': st.session_state.session_id}
102
+ )
103
 
 
104
  # If the run is completed, display the messages
105
  elif hasattr(st.session_state.run, 'status') and st.session_state.run.status == "completed":
106
  # Retrieve the list of messages
 
124
 
125
 
126
 
127
+ prompt = st.text_input("Wie kann ich dir helfen?")
128
+ if st.button("Submit"):
 
129
 
130
 
131
  # Add message to the thread