Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,14 +15,10 @@ import re
|
|
15 |
import textract
|
16 |
import zipfile
|
17 |
import random
|
18 |
-
|
19 |
import httpx # add 11/13/23
|
20 |
import asyncio
|
21 |
from openai import OpenAI
|
22 |
#from openai import AsyncOpenAI
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
from datetime import datetime
|
27 |
from xml.etree import ElementTree as ET
|
28 |
from bs4 import BeautifulSoup
|
@@ -40,8 +36,11 @@ from templates import css, bot_template, user_template
|
|
40 |
from io import BytesIO
|
41 |
from contextlib import redirect_stdout
|
42 |
|
43 |
-
|
|
|
44 |
st.set_page_config(page_title="Python AI Pair Programmer", layout="wide")
|
|
|
|
|
45 |
should_save = st.sidebar.checkbox("💾 Save", value=True)
|
46 |
col1, col2, col3, col4 = st.columns(4)
|
47 |
with col1:
|
@@ -51,12 +50,9 @@ with col1:
|
|
51 |
choice = st.sidebar.selectbox("Output File Type:", menu)
|
52 |
model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
|
53 |
|
54 |
-
|
55 |
# Define a context dictionary to maintain the state between exec calls
|
56 |
context = {}
|
57 |
|
58 |
-
|
59 |
-
|
60 |
def create_file(filename, prompt, response, should_save=True):
|
61 |
if not should_save:
|
62 |
return
|
@@ -94,7 +90,7 @@ def create_file(filename, prompt, response, should_save=True):
|
|
94 |
code_output = sys.stdout.getvalue()
|
95 |
combined_content += f"```\n{code_output}\n```\n\n"
|
96 |
realtimeEvalResponse = "# Code Results 🚀\n" + "```" + code_output + "```\n\n"
|
97 |
-
|
98 |
|
99 |
except Exception as e:
|
100 |
combined_content += f"```python\nError executing Python code: {e}\n```\n\n"
|
@@ -109,7 +105,7 @@ def create_file(filename, prompt, response, should_save=True):
|
|
109 |
if should_save:
|
110 |
with open(f"{base_filename}.md", 'w') as file:
|
111 |
file.write(combined_content)
|
112 |
-
st.
|
113 |
|
114 |
# Create a Base64 encoded link for the file
|
115 |
with open(f"{base_filename}.md", 'rb') as file:
|
|
|
15 |
import textract
|
16 |
import zipfile
|
17 |
import random
|
|
|
18 |
import httpx # add 11/13/23
|
19 |
import asyncio
|
20 |
from openai import OpenAI
|
21 |
#from openai import AsyncOpenAI
|
|
|
|
|
|
|
22 |
from datetime import datetime
|
23 |
from xml.etree import ElementTree as ET
|
24 |
from bs4 import BeautifulSoup
|
|
|
36 |
from io import BytesIO
|
37 |
from contextlib import redirect_stdout
|
38 |
|
39 |
+
|
40 |
+
# set page config once
|
41 |
st.set_page_config(page_title="Python AI Pair Programmer", layout="wide")
|
42 |
+
|
43 |
+
# UI for sidebar controls
|
44 |
should_save = st.sidebar.checkbox("💾 Save", value=True)
|
45 |
col1, col2, col3, col4 = st.columns(4)
|
46 |
with col1:
|
|
|
50 |
choice = st.sidebar.selectbox("Output File Type:", menu)
|
51 |
model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
|
52 |
|
|
|
53 |
# Define a context dictionary to maintain the state between exec calls
|
54 |
context = {}
|
55 |
|
|
|
|
|
56 |
def create_file(filename, prompt, response, should_save=True):
|
57 |
if not should_save:
|
58 |
return
|
|
|
90 |
code_output = sys.stdout.getvalue()
|
91 |
combined_content += f"```\n{code_output}\n```\n\n"
|
92 |
realtimeEvalResponse = "# Code Results 🚀\n" + "```" + code_output + "```\n\n"
|
93 |
+
st.code(realtimeEvalResponse)
|
94 |
|
95 |
except Exception as e:
|
96 |
combined_content += f"```python\nError executing Python code: {e}\n```\n\n"
|
|
|
105 |
if should_save:
|
106 |
with open(f"{base_filename}.md", 'w') as file:
|
107 |
file.write(combined_content)
|
108 |
+
st.code(combined_content)
|
109 |
|
110 |
# Create a Base64 encoded link for the file
|
111 |
with open(f"{base_filename}.md", 'rb') as file:
|