-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.py
More file actions
79 lines (60 loc) · 2.07 KB
/
shell.py
File metadata and controls
79 lines (60 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
if __name__ == "__main__": print("Wait while the model is loading...")
import requests
import os, json, shutil
import src.extract_images as extract_images
import src.AI_detect as AI_detect
def match_and_parse(filenames, pm):
res = AI_detect.predict_text(filenames, pm)
return [res[filenames[i]] for i in range(len(filenames))]
def proccess_request(basedir : str, prompts : list):
filenames = extract_images.find_files(basedir)
count = [0 for i in range(len(filenames))]
for pm in prompts:
now = match_and_parse(filenames, pm)
for i in range(len(count)):
count[i] += now[i]
for i in range(len(count)):
count[i] /= len(prompts)
count[i] *= 100
ans = list(zip(count, filenames))
ans.sort()
ans.reverse()
return ans
def main():
basedir = input("Enter base directory: ")
if not os.path.exists(basedir):
print("Path not found")
exit(-1)
count = 0
try:
count = int(input("Enter amount of prompts: "))
if count <= 0:
raise Exception
except:
print("Must be a positive integer")
exit(-1)
prompts = []
print("Enter prompts:")
for _ in range(count):
prompts.append(input("-> "))
#process the request, run the ai model and return a parsed result.
ans = proccess_request(basedir, prompts)
print("Finished processing, move results to a new directory?")
move = input("yes/no ")
if move.lower().find("yes") != -1:
move = input("dir: ")
else:
move = None
if move is not None and not os.path.exists(move):
os.makedirs(move)
#While user requests, print a new detection.
count = 0
for confid, path in ans:
print(round(confid / ans[0][0], 8), " : ", path, end=" ")
#to make easier to scp to local
if move is not None:
shutil.copyfile(path, os.path.join(move, str(count)) + "." + path.split(".")[-1])
count += 1
input()
if __name__ == '__main__':
main()