mike dupont commited on
Commit
3976141
1 Parent(s): 51877c2
Files changed (1) hide show
  1. app.py +40 -59
app.py CHANGED
@@ -1,17 +1,15 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import numpy as np
4
  import os
5
  import sys
6
- from glob import glob
7
  import subprocess
8
-
 
9
  st.title('Welcome to introspector lang_agent!!')
10
 
11
 
12
- limit = st.number_input("limit",value=40)
13
- url = st.text_input("url",value="http://localhost:11434")
14
- prompt = st.text_input("prompt",value="Consider this text as a creative writing prompt: ")
 
15
 
16
  source_data = st.selectbox(
17
  'What data source should we read',
@@ -22,100 +20,83 @@ source_data = st.selectbox(
22
 
23
  st.write('You selected:', source_data)
24
 
25
- #in python read directory source_data recursivly and print it in select box in streamlit
26
-
27
 
28
 
29
  def get_files(path='.'):
30
  """Recursive function to find all files in given directory path."""
31
- files = []
32
  for item in os.listdir(path):
33
  fp = os.path.join(path, item)
34
  if os.path.isdir(fp):
35
- files.append(fp)
36
- files += get_files(fp)
37
- return files
 
38
 
39
  files = get_files(source_data)
 
40
  if len(files) > limit:
41
  files = files[0:limit]
42
- #st.write(files)
43
 
44
  mode = st.selectbox("mode", [
45
  "--ollama",
46
  "--openai",
47
 
48
  ])
49
- model = st.selectbox("model", ["mistral","mixtral"])
50
 
51
- input_dir = st.selectbox("Select a file", files)
52
- st.write(f"You selected file: {input_dir}")
53
 
54
- if st.button("Process data",key="process"):
55
- prompt = prompt.replace("\"","\'")
56
  cmd = ["bash",
57
  "./run_agent.sh",
58
  input_dir,
59
  url,
60
  mode,
61
  model,
62
- "\"{prompt}\""]
63
  p = subprocess.Popen(cmd,
64
  stdout=subprocess.PIPE,
65
  stderr=subprocess.PIPE,
66
  )
67
  readable = {
68
- p.stdout.fileno(): sys.stdout.buffer, # log separately
69
  p.stderr.fileno(): sys.stderr.buffer,
70
  }
71
  while readable:
72
  for fd in select(readable, [], [])[0]:
73
- data = os.read(fd, 1024) # read available
74
- if not data: # EOF
75
  del readable[fd]
76
  else:
77
  st.write(data.decode("utf-8"))
78
  readable[fd].write(data)
79
- readable[fd].flush()
80
-
81
- ##
82
- def get_out_files(path='.'):
83
- """Recursive function to find all files in given directory path."""
84
- files = []
85
- for item in os.listdir(path):
86
- fp = os.path.join(path, item)
87
- if os.path.isdir(fp):
88
- files.append(fp)
89
- files += get_out_files(fp)
90
- else:
91
- if fp.endswith(".test"):
92
- files.append(fp)
93
- #st.write(fp)
94
- else:
95
- #st.write("skip"+fp)
96
- pass
97
- return files
98
 
 
99
 
100
 
101
- ### output
102
-
103
  def get_out_files(path='.'):
104
  """Recursive function to find all files in given directory path."""
105
- files = []
106
  for item in os.listdir(path):
107
- fp = os.path.join(path, item)
108
- if os.path.isdir(fp):
109
- files.append(fp)
110
- files += get_out_files(fp)
111
  else:
112
- if fp.endswith(".test"):
113
- files.append(fp)
114
- #st.write(fp)
115
  else:
116
- #st.write("skip"+fp)
117
  pass
118
- return files
 
119
 
120
  # scan1
121
  if st.button(f"Scan output {input_dir}", key=input_dir):
@@ -123,18 +104,18 @@ if st.button(f"Scan output {input_dir}", key=input_dir):
123
  outfiles = get_out_files(input_dir)
124
  if len(outfiles) > limit:
125
  outfiles = outfiles[0:limit]
126
- #st.write(outfiles)
127
 
128
  for x in outfiles:
129
  if os.path.isdir(x):
130
  pass
131
  else:
132
- (p,f) =os.path.split(x)
133
- with open(x, "r") as fp:
134
  btn = st.download_button(
135
  key=x,
136
  label="Download text" + x,
137
- data=fp,
138
  file_name=f,
139
  mime="application/text"
140
  )
 
 
 
 
1
  import os
2
  import sys
 
3
  import subprocess
4
+ from select import select
5
+ import streamlit as st
6
  st.title('Welcome to introspector lang_agent!!')
7
 
8
 
9
+
10
+ url = st.text_input("url", value="http://localhost:11434")
11
+ prompt = st.text_input(
12
+ "prompt", value="Consider this text as a creative writing prompt: ")
13
 
14
  source_data = st.selectbox(
15
  'What data source should we read',
 
20
 
21
  st.write('You selected:', source_data)
22
 
23
+ # in python read directory source_data recursivly and print it in select box in streamlit
 
24
 
25
 
26
  def get_files(path='.'):
27
  """Recursive function to find all files in given directory path."""
28
+ files2 = []
29
  for item in os.listdir(path):
30
  fp = os.path.join(path, item)
31
  if os.path.isdir(fp):
32
+ files2.append(fp)
33
+ files2 += get_files(fp)
34
+ return files2
35
+
36
 
37
  files = get_files(source_data)
38
+ limit = st.number_input("limit number of files show", value=40)
39
  if len(files) > limit:
40
  files = files[0:limit]
41
+ # st.write(files)
42
 
43
  mode = st.selectbox("mode", [
44
  "--ollama",
45
  "--openai",
46
 
47
  ])
48
+ model = st.selectbox("model", ["mistral", "mixtral"])
49
 
50
+ input_dir = st.selectbox("Select a directory to process", files)
51
+ st.write(f"You selected directory: {input_dir}")
52
 
53
+ if st.button("Process data", key="process"):
54
+ prompt = prompt.replace("\"", "\'")
55
  cmd = ["bash",
56
  "./run_agent.sh",
57
  input_dir,
58
  url,
59
  mode,
60
  model,
61
+ "\"{prompt}\""]
62
  p = subprocess.Popen(cmd,
63
  stdout=subprocess.PIPE,
64
  stderr=subprocess.PIPE,
65
  )
66
  readable = {
67
+ p.stdout.fileno(): sys.stdout.buffer, # log separately
68
  p.stderr.fileno(): sys.stderr.buffer,
69
  }
70
  while readable:
71
  for fd in select(readable, [], [])[0]:
72
+ data = os.read(fd, 1024) # read available
73
+ if not data: # EOF
74
  del readable[fd]
75
  else:
76
  st.write(data.decode("utf-8"))
77
  readable[fd].write(data)
78
+ readable[fd].flush()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
+ ##
81
 
82
 
 
 
83
  def get_out_files(path='.'):
84
  """Recursive function to find all files in given directory path."""
85
+ files2 = []
86
  for item in os.listdir(path):
87
+ fp2 = os.path.join(path, item)
88
+ if os.path.isdir(fp2):
89
+ files2.append(fp2)
90
+ files2 += get_out_files(fp2)
91
  else:
92
+ if fp2.endswith(".test"):
93
+ files2.append(fp2)
94
+ # st.write(fp)
95
  else:
96
+ # st.write("skip"+fp)
97
  pass
98
+ return files2
99
+
100
 
101
  # scan1
102
  if st.button(f"Scan output {input_dir}", key=input_dir):
 
104
  outfiles = get_out_files(input_dir)
105
  if len(outfiles) > limit:
106
  outfiles = outfiles[0:limit]
107
+ # st.write(outfiles)
108
 
109
  for x in outfiles:
110
  if os.path.isdir(x):
111
  pass
112
  else:
113
+ (p, f) = os.path.split(x)
114
+ with open(x, "r") as fp2:
115
  btn = st.download_button(
116
  key=x,
117
  label="Download text" + x,
118
+ data=fp2,
119
  file_name=f,
120
  mime="application/text"
121
  )