Spaces:
Runtime error
Runtime error
Update app.py
Browse files14 unmodified lines151617181819202123242522232411 unmodified lines3637384339404142434445463 unmodified lines50515254535455585956575831 unmodified lines90919297939495968 unmodified lines10510610711210810911011114 unmodified linesimport textractimport zipfile import random
import httpx # add 11/13/23import asynciofrom openai import OpenAI#from openai import AsyncOpenAI
from 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 variables
# 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 lines choice = 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 lines code_output = sys.stdout.getvalue() combined_content += f"```\n{code_output}\n```\n\n" realtimeEvalResponse = "# Code Results 🚀\n" + "```" + code_output + "```\n\n" # st.write(realtimeEvalResponse) st.code(realtimeEvalResponse) except Exception as e: combined_content += f"```python\nError executing Python code: {e}\n```\n\n"8 unmodified lines if should_save: with open(f"{base_filename}.md", 'w') as file: file.write(combined_content) st.write(combined_content) st.code(combined_content)
# Create a Base64 encoded link for the file with open(f"{base_filename}.md", 'rb') as file:app.py+6-10