Spaces:
Runtime error
Runtime error
Update app.py
Browse files14 unmodified lines151617181920212223242526272811 unmodified lines40414243444546473 unmodified lines51525354555657585960616231 unmodified lines9495969798991008 unmodified lines10911011111211311411514 unmodified linesimport textractimport zipfileimport randomimport httpx # add 11/13/23import asynciofrom openai import OpenAI#from openai import AsyncOpenAIfrom datetime import datetimefrom xml.etree import ElementTree as ETfrom bs4 import BeautifulSoup11 unmodified linesfrom io import BytesIOfrom contextlib import redirect_stdout# page config and sidebar declares up front allow all other functions to see global class variablesst.set_page_config(page_title="Python AI Pair Programmer", layout="wide")should_save = st.sidebar.checkbox("💾 Save", value=True)col1, col2, col3, col4 = st.columns(4)with col1:3 unmodified lineschoice = st.sidebar.selectbox("Output File Type:", menu)model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))# Define a context dictionary to maintain the state between exec callscontext = {}def create_file(filename, prompt, response, should_save=True):if not should_save:return31 unmodified linescode_output = sys.stdout.getvalue()combined_content += f"```\n{code_output}\n```\n\n"realtimeEvalResponse = "# Code Results 🚀\n" + "```" + code_output + "```\n\n"# st.write(realtimeEvalResponse)except Exception as e:combined_content += f"```python\nError executing Python code: {e}\n```\n\n"8 unmodified linesif should_save:with open(f"{base_filename}.md", 'w') as file:file.write(combined_content)st.write(combined_content)# Create a Base64 encoded link for the filewith open(f"{base_filename}.md", 'rb') as file:14 unmodified lines1516171819202122232411 unmodified lines36373839404142434445463 unmodified lines50515253545556575831 unmodified lines909192939495968 unmodified lines10510610710810911011114 unmodified linesimport textractimport zipfileimport randomimport httpx # add 11/13/23import asynciofrom openai import OpenAI#from openai import AsyncOpenAIfrom datetime import datetimefrom xml.etree import ElementTree as ETfrom bs4 import BeautifulSoup11 unmodified linesfrom io import BytesIOfrom contextlib import redirect_stdout# set page config oncest.set_page_config(page_title="Python AI Pair Programmer", layout="wide")# UI for sidebar controlsshould_save = st.sidebar.checkbox("💾 Save", value=True)col1, col2, col3, col4 = st.columns(4)with col1:3 unmodified lineschoice = st.sidebar.selectbox("Output File Type:", menu)model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))# Define a context dictionary to maintain the state between exec callscontext = {}def create_file(filename, prompt, response, should_save=True):if not should_save:return31 unmodified linescode_output = sys.stdout.getvalue()combined_content += f"```\n{code_output}\n```\n\n"realtimeEvalResponse = "# Code Results 🚀\n" + "```" + code_output + "```\n\n"st.code(realtimeEvalResponse)except Exception as e:combined_content += f"```python\nError executing Python code: {e}\n```\n\n"8 unmodified linesif should_save:with open(f"{base_filename}.md", 'w') as file:file.write(combined_content)st.code(combined_content)# Create a Base64 encoded link for the filewith open(f"{base_filename}.md", 'rb') as file:
app.py+6-10