fix python parsing, update deps
python parsing was broken & openai changed their internal APImaster
parent
66fb2933c9
commit
da74e67ecd
|
@ -299,11 +299,11 @@
|
||||||
},
|
},
|
||||||
"revchatgpt": {
|
"revchatgpt": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:36860b0297d5e846172c2fcfcdf27b4f19b80eac299b4e00c93a5dccf27f18c1",
|
"sha256:6217e51914300123bc01f1519de68eeece8bdca0aa68bca71e540d293cbbc23c",
|
||||||
"sha256:3fce7e348a8817e4335130a9ab2e523633c8c49cad1d2ca577571aeaa4a00115"
|
"sha256:fcebca9815761b6fcb5abbfb8b28bbee810d2a01fc148c19429066818a29d933"
|
||||||
],
|
],
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==0.0.23.5"
|
"version": "==0.0.30"
|
||||||
},
|
},
|
||||||
"six": {
|
"six": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
|
import json
|
||||||
import yaml
|
import yaml
|
||||||
from yaml import CLoader, CDumper
|
from yaml import CLoader, CDumper
|
||||||
from revChatGPT.revChatGPT import Chatbot
|
from revChatGPT.revChatGPT import Chatbot
|
||||||
import os
|
import os
|
||||||
from sys import argv
|
from sys import argv
|
||||||
import re
|
from parse import py
|
||||||
|
|
||||||
# from argparse import ArgumentParser
|
# from argparse import ArgumentParser
|
||||||
|
|
||||||
|
@ -23,39 +24,20 @@ infile = open(argv[1], "r")
|
||||||
# print(infile)
|
# print(infile)
|
||||||
|
|
||||||
# top level functions only for now
|
# top level functions only for now
|
||||||
functions = []
|
functions = py.find_toplevel_funcs(infile)
|
||||||
function_head = ""
|
|
||||||
function_content = ""
|
|
||||||
function_body_indent_level = 0
|
|
||||||
for line in infile:
|
|
||||||
curr_indent_level = len(line) - len(line.lstrip())
|
|
||||||
function_found = re.search('^def(\s+)(.*)\(.*\)(\s*):$', line.strip())
|
|
||||||
if function_found and len(function_head) == 0:
|
|
||||||
function_head = re.search("(\s+)(.*)\(.*\)", line).string.replace('def', '').replace('):', ')').strip()
|
|
||||||
function_content = line
|
|
||||||
function_body_indent_level = curr_indent_level + 1
|
|
||||||
|
|
||||||
elif len(function_head) > 0 and (curr_indent_level < function_body_indent_level):
|
|
||||||
functions.append({
|
|
||||||
"head": function_head,
|
|
||||||
"content": function_content
|
|
||||||
})
|
|
||||||
if function_found:
|
|
||||||
function_head = ""
|
|
||||||
function_content = ""
|
|
||||||
|
|
||||||
elif len(function_head) > 0 and curr_indent_level >= function_body_indent_level:
|
|
||||||
function_content += line
|
|
||||||
|
|
||||||
print(f"Found {len(functions)} functions.")
|
print(f"Found {len(functions)} functions.")
|
||||||
|
|
||||||
doc_prompt_head = "Explain what this function does in one short sentence, then give example code that uses the function:\n"
|
doc_prompt_head = "Explain what this function does in one short sentence, then give example code that uses the function:\n"
|
||||||
# doc_prompt_example = "Return only example code using this function:\n"
|
# doc_prompt_example = "Return only example code using this function:\n"
|
||||||
|
|
||||||
|
# for function in functions:
|
||||||
|
# print(function["content"])
|
||||||
|
# print("------------------")
|
||||||
|
|
||||||
bot = Chatbot({
|
bot = Chatbot({
|
||||||
'Authorization': config['Authorization'],
|
'Authorization': config['Authorization'],
|
||||||
'session_token': config['session_token'],
|
'session_token': config['session_token'],
|
||||||
# 'session': config['password']
|
|
||||||
}, conversation_id=None)
|
}, conversation_id=None)
|
||||||
|
|
||||||
bot.refresh_session()
|
bot.refresh_session()
|
||||||
|
|
|
@ -1,58 +1,101 @@
|
||||||
# Documentation for `example_code.py`
|
# Documentation for `example/example_code.py`
|
||||||
|
|
||||||
## `remove_dirt(image)`
|
## `remove_dirt(image)`
|
||||||
This function removes small dirt and noise from a binary image by closing small holes and removing small objects.
|
This function removes small elements from an image using area closing morphological operation.
|
||||||
|
|
||||||
Here is an example of how to use the function:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
import skimage.morphology as morphology
|
# Import the required module
|
||||||
from skimage import data
|
from skimage import morphology
|
||||||
|
|
||||||
# Load a binary image
|
# Load the image
|
||||||
image = data.coins() > 100
|
image = skimage.io.imread('image.jpg')
|
||||||
|
|
||||||
# Remove dirt from the image
|
# Apply the function to remove small elements from the image
|
||||||
cleaned_image = remove_dirt(image)
|
image = remove_dirt(image)
|
||||||
|
|
||||||
|
# Show the result
|
||||||
|
skimage.io.imshow(image)
|
||||||
|
```
|
||||||
|
|
||||||
|
## `calculate_area(countour)`
|
||||||
|
This function calculates the area of a contour in an image.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Import the required modules
|
||||||
|
import cv2 as cv
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# Load the image and find the contours
|
||||||
|
image = cv.imread('image.jpg')
|
||||||
|
contours, _ = cv.findContours(image, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
|
||||||
|
|
||||||
|
# Iterate over the contours and calculate their areas
|
||||||
|
for contour in contours:
|
||||||
|
area = calculate_area(contour)
|
||||||
|
print('Area of contour:', area)
|
||||||
```
|
```
|
||||||
|
|
||||||
## `center_of_mass(X)`
|
## `center_of_mass(X)`
|
||||||
This function calculates the center of mass of a 2D shape defined by a set of points.
|
This function calculates the center of mass of a set of points.
|
||||||
|
|
||||||
Here is an example of how to use the function:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
# Define a set of points that define a shape
|
# Define a set of points
|
||||||
X = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
|
X = np.array([[1,2], [3,4], [5,6]])
|
||||||
|
|
||||||
# Calculate the center of mass of the shape
|
# Calculate the center of mass of the points
|
||||||
center_of_mass = center_of_mass(X)
|
center = center_of_mass(X)
|
||||||
|
|
||||||
# Print the center of mass
|
# Print the result
|
||||||
print(center_of_mass)
|
print('Center of mass:', center)
|
||||||
```
|
```
|
||||||
|
|
||||||
The output will be `[0.5, 0.5]`, which is the coordinates of the center of the square defined by the points `X`.
|
The output will be `Center of mass: [3. 4.]`.
|
||||||
|
|
||||||
## `center_of_mass(X)`
|
## `center_of_mass(X)`
|
||||||
This function calculates the center of mass of a 2D shape defined by a set of points.
|
This function calculates the center of mass of a set of points.
|
||||||
|
|
||||||
Here is an example of how to use the function:
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
# Define a set of points that define a shape
|
# Define a set of points
|
||||||
X = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
|
X = np.array([[1,2], [3,4], [5,6]])
|
||||||
|
|
||||||
# Calculate the center of mass of the shape
|
# Calculate the center of mass of the points
|
||||||
center_of_mass = center_of_mass(X)
|
center = center_of_mass(X)
|
||||||
|
|
||||||
# Print the center of mass
|
# Print the result
|
||||||
print(center_of_mass)
|
print('Center of mass:', center)
|
||||||
```
|
```
|
||||||
|
|
||||||
The output will be `[0.5, 0.5]`, which is the coordinates of the center of the square defined by the points `X`.
|
The output will be `Center of mass: [3. 4.]`.
|
||||||
|
|
||||||
|
## `rg_ratio_normalize(imgarr)`
|
||||||
|
This function normalizes the temperature values in an image array using the RG ratio and a pyrometry calibration formula.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
# Import the required modules
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
# Load the image array
|
||||||
|
imgarr = np.array(...)
|
||||||
|
|
||||||
|
# Normalize the temperature values in the image
|
||||||
|
imgnew, tmin, tmax = rg_ratio_normalize(imgarr)
|
||||||
|
|
||||||
|
# Print the resulting minimum and maximum temperature values
|
||||||
|
print('Minimum temperature:', tmin)
|
||||||
|
print('Maximum temperature:', tmax)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,14 @@ def remove_dirt(image):
|
||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
def calculate_area(countour):
|
def calculate_area(countour):
|
||||||
c = np.expand_dims(countour.astype(np.float32), 1)
|
c = np.expand_dims(countour.astype(np.float32), 1)
|
||||||
c = cv.UMat(c)
|
c = cv.UMat(c)
|
||||||
|
|
||||||
return cv.contourArea(c)
|
return cv.contourArea(c)
|
||||||
|
|
||||||
|
|
||||||
def center_of_mass(X):
|
def center_of_mass(X):
|
||||||
x = X[:,0]
|
x = X[:,0]
|
||||||
y = X[:,1]
|
y = X[:,1]
|
||||||
|
@ -22,6 +24,7 @@ def center_of_mass(X):
|
||||||
|
|
||||||
img = remove_dirt(thresh_gray)
|
img = remove_dirt(thresh_gray)
|
||||||
|
|
||||||
|
|
||||||
def rg_ratio_normalize(imgarr):
|
def rg_ratio_normalize(imgarr):
|
||||||
# set max & min to most extreme values,
|
# set max & min to most extreme values,
|
||||||
# work up & down respectively from there
|
# work up & down respectively from there
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import re
|
||||||
|
|
||||||
|
def find_toplevel_funcs(lines):
|
||||||
|
functions = []
|
||||||
|
function_head = ""
|
||||||
|
function_content = ""
|
||||||
|
function_body_indent_level = 0
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
curr_indent_level = len(line) - len(line.lstrip())
|
||||||
|
function_found = re.search('^def(\s+)(.*)\(.*\)(\s*):(\s*)$', line.strip())
|
||||||
|
|
||||||
|
if len(function_head.strip()) > 0 and (curr_indent_level < function_body_indent_level):
|
||||||
|
functions.append({
|
||||||
|
"head": function_head,
|
||||||
|
"content": function_content
|
||||||
|
})
|
||||||
|
if function_found:
|
||||||
|
function_head = ""
|
||||||
|
function_content = ""
|
||||||
|
|
||||||
|
if function_found and len(function_head) == 0:
|
||||||
|
function_head = re.search("(\s+)(.*)\(.*\)", line).string.replace('def', '').replace('):', ')').strip()
|
||||||
|
function_content = line
|
||||||
|
function_body_indent_level = curr_indent_level + 1
|
||||||
|
|
||||||
|
elif not function_found and len(function_head.strip()) > 0 and curr_indent_level >= function_body_indent_level:
|
||||||
|
function_content += line
|
||||||
|
|
||||||
|
return functions
|
Loading…
Reference in New Issue