Spaces:
Runtime error
Runtime error
Update app.py
Browse files149 unmodified lines15015115215315315415515626 unmodified lines1831841851861871881891901911921931941951961971981992002012022032042052061861871886 unmodified lines19519619721919819920020120220322620420520620720820923221021121221316 unmodified lines2302312322332342352362374 unmodified lines242243244245246247248249250251252253254268255256257258259260261262263264265149 unmodified lines# Chat and Chat with filesdef chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'): model = model_choice conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}] conversation = [{'role': 'system', 'content': 'You are a python script writer.'}] conversation.append({'role': 'user', 'content': prompt}) if len(document_section)>0: conversation.append({'role': 'assistant', 'content': document_section})26 unmodified lines except: st.write(' ') full_reply_content = all_content
#for chunk in client.chat.completions.create( # model='gpt-3.5-turbo', # messages=conversation, # temperature=0.5, # stream=True #): # collected_chunks.append(chunk) # save the event response # chunk_message = chunk['choices'][0]['delta'] # extract the message # collected_messages.append(chunk_message) # save the message # content=chunk["choices"][0].get("delta",{}).get("content") # try: # report.append(content) # if len(content) > 0: # result = "".join(report).strip() # res_box.markdown(f'*{result}*') # except: # st.write(' ') # full_reply_content = ''.join([m.get('content', '') for m in collected_messages]) st.write("Elapsed time:") st.write(time.time() - start_time) readitaloud(full_reply_content)6 unmodified lines conversation.append({'role': 'user', 'content': prompt}) if len(file_content)>0: conversation.append({'role': 'assistant', 'content': file_content}) client = OpenAI( api_key= os.getenv('OPENAI_API_KEY') ) response = client.chat.completions.create(model=model_choice, messages=conversation) return response['choices'][0]['message']['content']
def link_button_with_emoji(url, title, emoji_summary): emojis = ["π", "π₯", "π‘οΈ", "π©Ί", "π¬", "π", "π§ͺ", "π¨ββοΈ", "π©ββοΈ"] random_emoji = random.choice(emojis) st.markdown(f"[{random_emoji} {emoji_summary} - {title}]({url})")
# Python parts and their corresponding emojis# Python parts and their corresponding emojis, with expanded detailspython_parts = { "Data Types": "π", "Control Structures": "π", 16 unmodified lines "Libraries": "π (Numpy, Pandas, Matplotlib, TensorFlow, Requests)"}
# Placeholder for chat responsesresponse_placeholders = {}
# Function to display Python concepts with expanders and chat buttonsdef display_python_parts():4 unmodified lines prompt = f"Learn about {python_parts_extended[part]}" if st.button(f"Explore {part}", key=part): response = chat_with_model(prompt, part) response_placeholders[part] = response
# Display the chat response if available if part in response_placeholders: st.markdown(f"**Response:** {response_placeholders[part]}")
# Define function to add paper buttons and linksdef add_paper_buttons_and_links():
# Python Pair Programmer page = st.sidebar.radio("Choose a page:", ["Python Pair Programmer"]) if page == "Python Pair Programmer": display_python_parts()
col1, col2, col3, col4 = st.columns(4)
with col1:app.py+15-26