AhmedSSoliman commited on
Commit
c568b1c
1 Parent(s): 36031cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -8,6 +8,14 @@ import streamlit as st
8
 
9
  #st.title('Code Generation on the CoNaLa Dataset')
10
 
 
 
 
 
 
 
 
 
11
  class CodeGenerator:
12
  def __init__(self):
13
  self.tokenizer = AutoTokenizer.from_pretrained("AhmedSSoliman/MarianCG-CoNaLa-Large")
@@ -26,7 +34,7 @@ class CodeGenerator:
26
  def check_code(self, code):
27
  with open("temp.py", "w") as f:
28
  f.write(code)
29
- result = subprocess.run(["flake8", "temp.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
30
  output = result.stdout.decode()
31
  error = result.stderr.decode()
32
 
@@ -113,6 +121,7 @@ class CodeGenerator:
113
 
114
 
115
 
 
116
  import autopep8
117
  import black
118
  import isort
@@ -123,7 +132,7 @@ import autoimport
123
  class PythonCodeFormatter:
124
  def __init__(self, code):
125
  self.code = code.replace('▁', ' ').strip()
126
-
127
 
128
  def load_code_from_file(self, filename):
129
  # Load the code to be fixed
@@ -143,21 +152,17 @@ class PythonCodeFormatter:
143
 
144
  # Use autopep8 to fix any remaining issues
145
  formatted_code = autopep8.fix_code(formatted_code)
 
146
 
147
  except RuntimeError as error:
148
- if str(error) == 'Project root not found':
149
  return formatted_code
150
  else:
151
  raise # re-raise the error if it's not the one we're looking for
152
- except ValueError as error:
153
- if str(error) == 'Cannot parse: 2:0: EOF in multi-line statement':
154
- # add )) to the end of the line to fix the error
155
- self.code += '))'
156
- # retry the format() function with the corrected code
157
- formatted_code = self.format()
158
- else:
159
- raise # re-raise the error if it's not the one we're looking for
160
 
 
 
 
161
  return formatted_code
162
 
163
 
 
8
 
9
  #st.title('Code Generation on the CoNaLa Dataset')
10
 
11
+ import subprocess
12
+ import re
13
+ import pandas as pd
14
+ import plotly.express as px
15
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
16
+ from prettytable import PrettyTable
17
+
18
+
19
  class CodeGenerator:
20
  def __init__(self):
21
  self.tokenizer = AutoTokenizer.from_pretrained("AhmedSSoliman/MarianCG-CoNaLa-Large")
 
34
  def check_code(self, code):
35
  with open("temp.py", "w") as f:
36
  f.write(code)
37
+ result = subprocess.run(["flake8", "--count", "temp.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
38
  output = result.stdout.decode()
39
  error = result.stderr.decode()
40
 
 
121
 
122
 
123
 
124
+
125
  import autopep8
126
  import black
127
  import isort
 
132
  class PythonCodeFormatter:
133
  def __init__(self, code):
134
  self.code = code.replace('▁', ' ').strip()
135
+
136
 
137
  def load_code_from_file(self, filename):
138
  # Load the code to be fixed
 
152
 
153
  # Use autopep8 to fix any remaining issues
154
  formatted_code = autopep8.fix_code(formatted_code)
155
+ return formatted_code
156
 
157
  except RuntimeError as error:
158
+ if str(error) == 'Project root not found.':
159
  return formatted_code
160
  else:
161
  raise # re-raise the error if it's not the one we're looking for
 
 
 
 
 
 
 
 
162
 
163
+ except ValueError as error:
164
+ return formatted_code
165
+
166
  return formatted_code
167
 
168