Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -150,7 +150,7 @@ def generate_filename(prompt, file_type):
|
|
150 |
# Chat and Chat with files
|
151 |
def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
152 |
model = model_choice
|
153 |
-
conversation = [{'role': 'system', 'content': 'You are a
|
154 |
conversation.append({'role': 'user', 'content': prompt})
|
155 |
if len(document_section)>0:
|
156 |
conversation.append({'role': 'assistant', 'content': document_section})
|
@@ -183,27 +183,6 @@ def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
|
183 |
except:
|
184 |
st.write(' ')
|
185 |
full_reply_content = all_content
|
186 |
-
|
187 |
-
|
188 |
-
#for chunk in client.chat.completions.create(
|
189 |
-
# model='gpt-3.5-turbo',
|
190 |
-
# messages=conversation,
|
191 |
-
# temperature=0.5,
|
192 |
-
# stream=True
|
193 |
-
#):
|
194 |
-
# collected_chunks.append(chunk) # save the event response
|
195 |
-
# chunk_message = chunk['choices'][0]['delta'] # extract the message
|
196 |
-
# collected_messages.append(chunk_message) # save the message
|
197 |
-
# content=chunk["choices"][0].get("delta",{}).get("content")
|
198 |
-
# try:
|
199 |
-
# report.append(content)
|
200 |
-
# if len(content) > 0:
|
201 |
-
# result = "".join(report).strip()
|
202 |
-
# res_box.markdown(f'*{result}*')
|
203 |
-
# except:
|
204 |
-
# st.write(' ')
|
205 |
-
|
206 |
-
# full_reply_content = ''.join([m.get('content', '') for m in collected_messages])
|
207 |
st.write("Elapsed time:")
|
208 |
st.write(time.time() - start_time)
|
209 |
readitaloud(full_reply_content)
|
@@ -216,20 +195,19 @@ def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
|
|
216 |
conversation.append({'role': 'user', 'content': prompt})
|
217 |
if len(file_content)>0:
|
218 |
conversation.append({'role': 'assistant', 'content': file_content})
|
219 |
-
|
220 |
client = OpenAI(
|
221 |
api_key= os.getenv('OPENAI_API_KEY')
|
222 |
)
|
223 |
response = client.chat.completions.create(model=model_choice, messages=conversation)
|
224 |
return response['choices'][0]['message']['content']
|
225 |
|
226 |
-
|
227 |
def link_button_with_emoji(url, title, emoji_summary):
|
228 |
emojis = ["π", "π₯", "π‘οΈ", "π©Ί", "π¬", "π", "π§ͺ", "π¨ββοΈ", "π©ββοΈ"]
|
229 |
random_emoji = random.choice(emojis)
|
230 |
st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")
|
231 |
|
232 |
-
|
|
|
233 |
python_parts = {
|
234 |
"Data Types": "π",
|
235 |
"Control Structures": "π",
|
@@ -252,6 +230,8 @@ python_parts_extended = {
|
|
252 |
"Libraries": "π (Numpy, Pandas, Matplotlib, TensorFlow, Requests)"
|
253 |
}
|
254 |
|
|
|
|
|
255 |
|
256 |
# Function to display Python concepts with expanders and chat buttons
|
257 |
def display_python_parts():
|
@@ -262,15 +242,24 @@ def display_python_parts():
|
|
262 |
prompt = f"Learn about {python_parts_extended[part]}"
|
263 |
if st.button(f"Explore {part}", key=part):
|
264 |
response = chat_with_model(prompt, part)
|
|
|
265 |
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
# Define function to add paper buttons and links
|
267 |
def add_paper_buttons_and_links():
|
268 |
-
|
269 |
# Python Pair Programmer
|
270 |
page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"])
|
271 |
if page == "Python Pair Programmer":
|
272 |
display_python_parts()
|
273 |
|
|
|
|
|
|
|
274 |
col1, col2, col3, col4 = st.columns(4)
|
275 |
|
276 |
with col1:
|
|
|
150 |
# Chat and Chat with files
|
151 |
def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
152 |
model = model_choice
|
153 |
+
conversation = [{'role': 'system', 'content': 'You are a python script writer.'}]
|
154 |
conversation.append({'role': 'user', 'content': prompt})
|
155 |
if len(document_section)>0:
|
156 |
conversation.append({'role': 'assistant', 'content': document_section})
|
|
|
183 |
except:
|
184 |
st.write(' ')
|
185 |
full_reply_content = all_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
st.write("Elapsed time:")
|
187 |
st.write(time.time() - start_time)
|
188 |
readitaloud(full_reply_content)
|
|
|
195 |
conversation.append({'role': 'user', 'content': prompt})
|
196 |
if len(file_content)>0:
|
197 |
conversation.append({'role': 'assistant', 'content': file_content})
|
|
|
198 |
client = OpenAI(
|
199 |
api_key= os.getenv('OPENAI_API_KEY')
|
200 |
)
|
201 |
response = client.chat.completions.create(model=model_choice, messages=conversation)
|
202 |
return response['choices'][0]['message']['content']
|
203 |
|
|
|
204 |
def link_button_with_emoji(url, title, emoji_summary):
|
205 |
emojis = ["π", "π₯", "π‘οΈ", "π©Ί", "π¬", "π", "π§ͺ", "π¨ββοΈ", "π©ββοΈ"]
|
206 |
random_emoji = random.choice(emojis)
|
207 |
st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")
|
208 |
|
209 |
+
|
210 |
+
# Python parts and their corresponding emojis, with expanded details
|
211 |
python_parts = {
|
212 |
"Data Types": "π",
|
213 |
"Control Structures": "π",
|
|
|
230 |
"Libraries": "π (Numpy, Pandas, Matplotlib, TensorFlow, Requests)"
|
231 |
}
|
232 |
|
233 |
+
# Placeholder for chat responses
|
234 |
+
response_placeholders = {}
|
235 |
|
236 |
# Function to display Python concepts with expanders and chat buttons
|
237 |
def display_python_parts():
|
|
|
242 |
prompt = f"Learn about {python_parts_extended[part]}"
|
243 |
if st.button(f"Explore {part}", key=part):
|
244 |
response = chat_with_model(prompt, part)
|
245 |
+
response_placeholders[part] = response
|
246 |
|
247 |
+
# Display the chat response if available
|
248 |
+
if part in response_placeholders:
|
249 |
+
st.markdown(f"**Response:** {response_placeholders[part]}")
|
250 |
+
|
251 |
+
|
252 |
+
|
253 |
# Define function to add paper buttons and links
|
254 |
def add_paper_buttons_and_links():
|
|
|
255 |
# Python Pair Programmer
|
256 |
page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"])
|
257 |
if page == "Python Pair Programmer":
|
258 |
display_python_parts()
|
259 |
|
260 |
+
|
261 |
+
|
262 |
+
|
263 |
col1, col2, col3, col4 = st.columns(4)
|
264 |
|
265 |
with col1:
|