Skip to content

Commit

Permalink
added requirements.
Browse files Browse the repository at this point in the history
txt, modified readme, formatted ui
  • Loading branch information
Mayaaa311 committed Apr 25, 2024
1 parent 6eea187 commit 5f914ca
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 38 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@

# GPTLens Demo

GPT Lens is an LLM tool to check for security breaches in smart contracts. To learn more, go to : https://github.com/git-disl/GPTLens. This demo provides a scenario-based walkthrough of how GPTLens utilizes LLMs to examine smart contract code and detect vulnerabilities.


## Install requirement packages

```
pip install -r requirements.txt
```


## Run Demo

```
python GPTLens_demo/gui_test.py
python src/gui_test.py
```
13 changes: 3 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: win-64
openai==1.11.1
streamlit==1.31.0
tqdm==4.66.1
STqdm
# pyautogui
# python-xlib
streamlit_js_eval
pillow==10.3.0
PyMuPDF==1.24.2
PyMuPDFb==1.24.1
55 changes: 28 additions & 27 deletions src/gui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, root):
# Create an instance of Style widget
style=ttk.Style()
style.theme_use('clam')

self.font_size=12

self.create_images()
# self.setup_ui()
Expand Down Expand Up @@ -96,44 +96,45 @@ def make_cover_screen(self):
start_button.place(relx=0.5, rely=0.8, anchor="center") # Position the button relative to the window size

self.root.withdraw()

def show_pdf_slides(self):
self.cover_screen.destroy()
self.root.deiconify()

self.setup_scroll()
self.setup_scroll_and_window()

pdf_path = "src/assets/GPT-Lens-demo-slide.pdf"
pg=[]
for i in range(0,6):
pg.append(self.load_page(pdf_path,i))

self.title_bar_container = tk.Frame(self.main_frame,bg=self.color,highlightbackground="black", highlightthickness=0.5)
self.title_bar_container.pack(fill='x',padx=0)
self.slide_frame = tk.Frame(self.main_frame)
self.slide_frame.pack(fill='x',padx=0)
self.main_frame.grid_columnconfigure(0, weight=1)
self.title_bar_container.grid_columnconfigure(0, weight=1)
self.slide_frame.grid_columnconfigure(0, weight=1)
self.title_bar_container = tk.Frame(self.main_frame, bg=self.color, highlightbackground="black", highlightthickness=0.5)
self.title_bar_container.grid(row=0, column=0, sticky='ew') # Span across all columns horizontally
self.title_bar_container.grid_columnconfigure(0, minsize=1300) # Allow expansion of the column

label = tk.Label(self.title_bar_container, text="GPT-lens Architecture Overview", font=('Arial', 30, 'bold'),bg=self.color)
label.grid(row=0, column=0, sticky='n',pady=15,padx=10) # Span only the first column
label = tk.Label(self.title_bar_container, text="GPT-lens Architecture Overview", font=('Arial', 30, 'bold'), bg=self.color)
label.grid(row=0, column=0, sticky='new', pady=15, padx=10) # Span only the first column

label = tk.Label(self.title_bar_container,
text="""Scroll down to view a demonstration on GPT-Lens architecture, click 'Next' to go to data walkthrough""",
font=('Arial',14),
bg=self.color)
label.grid(row=1, column=0, sticky='n',pady=0,padx=10) # Span only the first column
text="Scroll down to view a demonstration on GPT-Lens architecture, click 'Next' to go to data walkthrough",
font=('Arial', 14),
bg=self.color)
label.grid(row=1, column=0, sticky='n', pady=0, padx=10) # Span only the first column

self.slide_frame = tk.Frame(self.main_frame)
self.slide_frame.grid(row=1,column=0, sticky='n') # Adjusted packing to span whole width
self.main_frame.grid_columnconfigure(0, weight=1)
self.slide_frame.grid_columnconfigure(0, weight=1)

# Create a label to display the image
for i,p in enumerate(pg):
pdf_label = tk.Label(self.slide_frame, image=p)
pdf_label.image = p # Keep a reference to prevent garbage collection
pdf_label.grid(row=i, column=1, sticky='n',pady=0,padx=10)
pdf_label.grid(row=i, column=1, sticky='n', pady=0, padx=10)

# Button to go to data walkthrough
data_button = tk.Button(self.main_frame, text="Next", command=self.setup_ui)
data_button.pack()
data_button.grid()



def load_page(self, path, page_n):
Expand All @@ -156,7 +157,7 @@ def setup_ui(self):
for widget in self.root.winfo_children():
widget.destroy()
self.root.deiconify()
self.setup_scroll()
self.setup_scroll_and_window()
self.setup_frames()

def update_font_size(self, event=None):
Expand All @@ -179,7 +180,7 @@ def update_font_size(self, event=None):
style = ttk.Style(self.root)
style.configure('Treeview', font=new_font)

def setup_scroll(self):
def setup_scroll_and_window(self):
# vertical scrollbar
scroll_y = tk.Scrollbar(self.root)
scroll_y.pack(side='right', fill='y')
Expand All @@ -188,20 +189,18 @@ def setup_scroll(self):
scroll_x = tk.Scrollbar(self.root, orient='horizontal')
scroll_x.pack(side='bottom', fill='x')

self.canvas = tk.Canvas(self.root, yscrollcommand=scroll_y.set,xscrollcommand=scroll_x.set)
self.canvas = tk.Canvas(self.root, yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set)
self.canvas.pack(side='left', fill='both', expand=True)

scroll_y.config(command=self.canvas.yview)
scroll_x.config(command=self.canvas.xview)


self.canvas.bind_all("<MouseWheel>", self.on_mousewheel)

self.main_frame = tk.Frame(self.canvas)
self.canvas.create_window((0, 0), window=self.main_frame)
self.canvas.create_window((0, 0), window=self.main_frame, anchor="nw") # Anchor to the northwest corner
self.main_frame.bind('<Configure>', lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all")))


def setup_frames(self):

# Add method calls to create different frames and load UI components
Expand All @@ -218,14 +217,15 @@ def create_ack(self):
label1 = tk.Label(self.acknowldgement, text="""Acknowledgement: This is a mini-project Yining Yuan did with GIT DiSL group under the supervision of Prof. Dr. Ling Liu
and PhD student Sihao Hu. For more detailed information on GPTLens, see the paper (https://arxiv.org/pdf/2310.01152.pdf) and open source code
(https://github.com/git-disl/GPTLens?tab=readme-ov-file) and for technical questions, consult with Sihao Hu.""",fg="gray")
label1.grid(row=0, column=2, sticky='n',padx=10)
label1.grid(row=0, column=0, sticky='n',padx=10)



def create_containers(self,color=None):

self.title_bar_container = tk.Frame(self.main_frame,bg=color,highlightbackground="black", highlightthickness=0.5)
self.title_bar_container.grid_columnconfigure(0, weight=1) # This will allow the column to expand
self.title_bar_container.grid_columnconfigure(0, minsize=1300)

self.dropdown_frame = tk.Frame(self.main_frame)
self.preprocessing_frame = tk.Frame(self.main_frame)
Expand All @@ -239,7 +239,8 @@ def create_containers(self,color=None):
self.ranker_container = tk.Frame(self.main_frame)
self.acknowldgement = tk.Frame(self.main_frame)

self.title_bar_container.pack(fill='x',padx=0)
self.title_bar_container.pack(fill='x', expand=True, padx=0)

self.dropdown_frame.pack(fill='x')

self.preprocessing_frame.pack(fill='x') # Pack the container frames vertically
Expand Down Expand Up @@ -269,7 +270,7 @@ def create_title(self,color=None):

self.settings_button = tk.Button(self.title_bar_container, image=self.settings_icon, command=self.on_settings_icon_click, borderwidth=0)
self.settings_button.image = self.settings_icon # Keep a reference to the image
self.settings_button.grid(row=0, column=0, sticky='ne',pady=5,padx=10)
self.settings_button.grid(row=0, column=0, sticky='nw',pady=5,padx=20)

def on_settings_icon_click(self):
# Method bound to the settings icon click event
Expand Down

0 comments on commit 5f914ca

Please sign in to comment.