Spaces:
Sleeping
Sleeping
thomasgauthier
commited on
Commit
·
4cf5293
1
Parent(s):
ea0c6a4
forgot some files
Browse files- __init__.py +0 -0
- requirements.txt +2 -1
- utils.py +21 -0
__init__.py
ADDED
File without changes
|
requirements.txt
CHANGED
@@ -6,4 +6,5 @@ pathvalidate==3.2.*
|
|
6 |
openai==1.3.*
|
7 |
jsonschema==4.17.*
|
8 |
numpy==1.22.*
|
9 |
-
uvicorn==0.23.*
|
|
|
|
6 |
openai==1.3.*
|
7 |
jsonschema==4.17.*
|
8 |
numpy==1.22.*
|
9 |
+
uvicorn==0.23.*
|
10 |
+
mistune==2.0.*
|
utils.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import mistune
|
2 |
+
|
3 |
+
# Define a renderer that inherits from the mistune Renderer
|
4 |
+
class CodeExtractor(mistune.HTMLRenderer):
|
5 |
+
def __init__(self):
|
6 |
+
super().__init__()
|
7 |
+
self.code_blocks = []
|
8 |
+
|
9 |
+
def block_code(self, code, info=None):
|
10 |
+
self.code_blocks.append(code)
|
11 |
+
return super().block_code(code, info)
|
12 |
+
|
13 |
+
def extract_code(markdown_text):
|
14 |
+
renderer = CodeExtractor()
|
15 |
+
markdown = mistune.create_markdown(renderer=renderer)
|
16 |
+
markdown(markdown_text)
|
17 |
+
code_blocks = renderer.code_blocks
|
18 |
+
|
19 |
+
found = [code for code in code_blocks if 'def transform_data(data):' in code]
|
20 |
+
|
21 |
+
return found[0] if len(found) > 0 else None
|