Spaces:
Runtime error
Runtime error
Haseeb
commited on
Commit
•
8d5b8ec
1
Parent(s):
e8cd164
Added Missing directories
Browse files- bardcode_interpreter.py +26 -11
- bash_src/clear_cache.sh +0 -5
- lib/bardcoder_lib.py +1 -1
bardcode_interpreter.py
CHANGED
@@ -13,18 +13,20 @@ Date : 21-05-2023
|
|
13 |
|
14 |
# Import the required libraries
|
15 |
import streamlit as st
|
16 |
-
from os import path
|
17 |
import time
|
18 |
import traceback
|
19 |
from lib.bardcoder_lib import BardCoder
|
20 |
import subprocess
|
21 |
from io import StringIO
|
22 |
-
import re
|
23 |
from lib.sharegpt_api import sharegpt_get_url
|
24 |
from lib.blacklist_commands import harmful_commands_python, harmful_commands_cpp, harmful_prompts
|
25 |
from PIL import Image
|
26 |
import tokenize
|
|
|
|
|
27 |
import io
|
|
|
|
|
28 |
|
29 |
# The input limit of Bard is 4,000 character (As per the Bard API documentation)
|
30 |
# But you can give more input upto 10,000 characters. so we are gonna stick to that.
|
@@ -389,24 +391,37 @@ def init_session_state():
|
|
389 |
if "file_char_count" not in st.session_state:
|
390 |
st.session_state.file_char_count = 0
|
391 |
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
filename = __file__
|
397 |
-
BardCoder.write_log(f"Making {filename} read-only")
|
398 |
-
os.chmod(filename, S_IREAD|S_IRGRP|S_IROTH)
|
399 |
|
400 |
# Make all files in lib folder read-only
|
401 |
-
folder
|
|
|
402 |
for filename in os.listdir(folder):
|
403 |
filepath = os.path.join(folder, filename)
|
404 |
os.chmod(filepath, S_IREAD|S_IRGRP|S_IROTH)
|
405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
406 |
if __name__ == "__main__":
|
407 |
try:
|
408 |
BardCoder.write_log("Starting the streamlit App")
|
409 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
|
411 |
# Load the CSS file named style.css
|
412 |
load_css("styles/style.css")
|
|
|
13 |
|
14 |
# Import the required libraries
|
15 |
import streamlit as st
|
|
|
16 |
import time
|
17 |
import traceback
|
18 |
from lib.bardcoder_lib import BardCoder
|
19 |
import subprocess
|
20 |
from io import StringIO
|
|
|
21 |
from lib.sharegpt_api import sharegpt_get_url
|
22 |
from lib.blacklist_commands import harmful_commands_python, harmful_commands_cpp, harmful_prompts
|
23 |
from PIL import Image
|
24 |
import tokenize
|
25 |
+
from stat import S_IREAD, S_IRGRP, S_IROTH
|
26 |
+
import re
|
27 |
import io
|
28 |
+
import os
|
29 |
+
from os import path
|
30 |
|
31 |
# The input limit of Bard is 4,000 character (As per the Bard API documentation)
|
32 |
# But you can give more input upto 10,000 characters. so we are gonna stick to that.
|
|
|
391 |
if "file_char_count" not in st.session_state:
|
392 |
st.session_state.file_char_count = 0
|
393 |
|
394 |
+
def make_code_interpreter_read_only(files=[],folders:str="lib"):
|
395 |
+
for filename in files:
|
396 |
+
BardCoder.write_log(f"Making {filename} read-only")
|
397 |
+
os.chmod(filename, S_IREAD|S_IRGRP|S_IROTH)
|
|
|
|
|
|
|
398 |
|
399 |
# Make all files in lib folder read-only
|
400 |
+
BardCoder.write_log(f"Making all files in {folders} folder read-only")
|
401 |
+
folder = folders
|
402 |
for filename in os.listdir(folder):
|
403 |
filepath = os.path.join(folder, filename)
|
404 |
os.chmod(filepath, S_IREAD|S_IRGRP|S_IROTH)
|
405 |
|
406 |
+
def create_dirs_on_startup():
|
407 |
+
# Create the uploads directory if it does not exist
|
408 |
+
if not os.path.exists("uploads"):
|
409 |
+
os.makedirs("uploads")
|
410 |
+
if not os.path.exists("codes"):
|
411 |
+
os.makedirs("codes")
|
412 |
+
if not os.path.exists("response"):
|
413 |
+
os.makedirs("response")
|
414 |
+
|
415 |
if __name__ == "__main__":
|
416 |
try:
|
417 |
BardCoder.write_log("Starting the streamlit App")
|
418 |
+
# Create directories on startup
|
419 |
+
create_dirs_on_startup()
|
420 |
+
|
421 |
+
# Make the code interpreter read-only
|
422 |
+
file = __file__
|
423 |
+
filenames = [file,file.replace("bardcode_interpreter", "bardcoder")]
|
424 |
+
make_code_interpreter_read_only(filenames,"lib")
|
425 |
|
426 |
# Load the CSS file named style.css
|
427 |
load_css("styles/style.css")
|
bash_src/clear_cache.sh
CHANGED
@@ -1,10 +1,5 @@
|
|
1 |
#!/bin/bash
|
2 |
|
3 |
-
# Create codes folder if it doesn't exist
|
4 |
-
if [ ! -d "codes" ]; then
|
5 |
-
mkdir codes
|
6 |
-
fi
|
7 |
-
|
8 |
# removing only all executables from codes.
|
9 |
file -F: codes/* | grep "executable" | cut -d: -f1 | xargs rm
|
10 |
|
|
|
1 |
#!/bin/bash
|
2 |
|
|
|
|
|
|
|
|
|
|
|
3 |
# removing only all executables from codes.
|
4 |
file -F: codes/* | grep "executable" | cut -d: -f1 | xargs rm
|
5 |
|
lib/bardcoder_lib.py
CHANGED
@@ -78,7 +78,7 @@ class BardCoder:
|
|
78 |
raise ValueError("Data cannot be None")
|
79 |
with open("bardcoder.log",'a') as f:
|
80 |
# Get the name of the calling function
|
81 |
-
caller_name = inspect.stack()[1][3]
|
82 |
f.write(f"{time.strftime('%d-%m-%Y %H:%M:%S')} {caller_name}: {data}\n")
|
83 |
|
84 |
# Set the api key
|
|
|
78 |
raise ValueError("Data cannot be None")
|
79 |
with open("bardcoder.log",'a') as f:
|
80 |
# Get the name of the calling function
|
81 |
+
caller_name = inspect.stack()[1][3]
|
82 |
f.write(f"{time.strftime('%d-%m-%Y %H:%M:%S')} {caller_name}: {data}\n")
|
83 |
|
84 |
# Set the api key
|