rudr4sarkar commited on
Commit
925739f
·
verified ·
1 Parent(s): f5539e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -49,7 +49,7 @@ def load_model():
49
 
50
  return model, tokenizer, device
51
 
52
- def analyze_contract(contract_code, model, tokenizer, device, batch_size=1):
53
  prompt = f"{contract_code}\n\nidentify vulnerability of this code given above"
54
 
55
  # Add padding token if needed
@@ -61,8 +61,7 @@ def analyze_contract(contract_code, model, tokenizer, device, batch_size=1):
61
  return_tensors="pt",
62
  padding=True,
63
  truncation=True,
64
- max_length=2048,
65
- batch_size=batch_size
66
  ).to(device)
67
 
68
  outputs = model.generate(
@@ -112,13 +111,11 @@ contract_code = st.text_area(
112
  placeholder="pragma solidity ^0.5.0;\n\ncontract YourContract {\n // Your code here\n}"
113
  )
114
 
115
- col1, col2, col3 = st.columns([1, 2, 1])
116
  with col1:
117
  analyze_button = st.button("Analyze Contract", type="primary")
118
  with col2:
119
  load_sample = st.button("Load Sample Contract")
120
- with col3:
121
- batch_size = st.number_input("Batch Size", min_value=1, max_value=8, value=1, step=1)
122
 
123
  # Sample contract button
124
  if load_sample:
@@ -160,17 +157,11 @@ contract Bank{
160
  if analyze_button and contract_code:
161
  try:
162
  with st.spinner('Analyzing contract...'):
163
- # Get the current available GPU memory
164
- if st.session_state.device == "cuda":
165
- gpu_stats = torch.cuda.get_device_properties(0)
166
- st.write(f"GPU Memory: {gpu_stats.total_memory / (1024 ** 2):.2f} MB")
167
-
168
  analysis = analyze_contract(
169
  contract_code,
170
  st.session_state.model,
171
  st.session_state.tokenizer,
172
- st.session_state.device,
173
- batch_size=batch_size
174
  )
175
 
176
  st.subheader("Analysis Results")
@@ -187,10 +178,6 @@ if analyze_button and contract_code:
187
  elif analyze_button:
188
  st.warning("Please enter some contract code to analyze.")
189
 
190
- # Display a warning about CPU performance
191
- if st.session_state.device == "cpu":
192
- st.warning("Running the model on CPU can be significantly slower. For better performance, consider using a GPU-enabled environment.")
193
-
194
  # Add footer with information
195
  st.markdown("---")
196
  st.markdown("""
 
49
 
50
  return model, tokenizer, device
51
 
52
+ def analyze_contract(contract_code, model, tokenizer, device):
53
  prompt = f"{contract_code}\n\nidentify vulnerability of this code given above"
54
 
55
  # Add padding token if needed
 
61
  return_tensors="pt",
62
  padding=True,
63
  truncation=True,
64
+ max_length=2048
 
65
  ).to(device)
66
 
67
  outputs = model.generate(
 
111
  placeholder="pragma solidity ^0.5.0;\n\ncontract YourContract {\n // Your code here\n}"
112
  )
113
 
114
+ col1, col2 = st.columns([1, 4])
115
  with col1:
116
  analyze_button = st.button("Analyze Contract", type="primary")
117
  with col2:
118
  load_sample = st.button("Load Sample Contract")
 
 
119
 
120
  # Sample contract button
121
  if load_sample:
 
157
  if analyze_button and contract_code:
158
  try:
159
  with st.spinner('Analyzing contract...'):
 
 
 
 
 
160
  analysis = analyze_contract(
161
  contract_code,
162
  st.session_state.model,
163
  st.session_state.tokenizer,
164
+ st.session_state.device
 
165
  )
166
 
167
  st.subheader("Analysis Results")
 
178
  elif analyze_button:
179
  st.warning("Please enter some contract code to analyze.")
180
 
 
 
 
 
181
  # Add footer with information
182
  st.markdown("---")
183
  st.markdown("""