File size: 4,398 Bytes
3ef37b3
 
 
a692df9
 
 
 
 
 
 
 
 
 
 
 
 
f9be86e
c924121
 
 
a692df9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f9be86e
a692df9
 
 
 
 
 
 
 
 
 
 
 
 
 
06731e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f9be86e
 
06731e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f9be86e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import streamlit as st
import pandas as pd
import numpy as np
import os
from glob import glob
import subprocess

st.title('Welcome to introspector lang_agent!!')


limit  = st.number_input("limit",value=40)
url  = st.text_input("url",value="http://localhost:11434")
prompt  = st.text_input("prompt",value="Consider this text as a creative writing prompt: ")

source_data = st.selectbox(
    'What data source should we read',
    (
        '/data',
        '/mnt/data1/2024/02/12/meta-coq-common/',
    ))

st.write('You selected:', source_data)

#in python read directory source_data recursivly and print it in select box in streamlit



def get_files(path='.'):
    """Recursive function to find all files in given directory path."""
    files = []
    for item in os.listdir(path):
        fp = os.path.join(path, item)
        if os.path.isdir(fp):
            files.append(fp)
            files += get_files(fp)
    return files

files = get_files(source_data)
if len(files) > limit:
    files = files[0:limit]
#st.write(files)

mode = st.selectbox("mode", [
    "--ollama",
    "--openai",

])
model = st.selectbox("model", ["mistral","mixtral"])

input_dir = st.selectbox("Select a file", files)
st.write(f"You selected file: {input_dir}")

if st.button("Process data"):
    prompt = prompt.replace("\"","\'")
    cmd = ["bash",
           "./run_agent.sh",
           input_dir,
           url,
           mode,
           model,
           "\"{prompt}\""]        
    p = subprocess.Popen(cmd,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE,
                         )
    readable = {
        p.stdout.fileno(): sys.stdout.buffer, # log separately
        p.stderr.fileno(): sys.stderr.buffer,
    }
    while readable:
        for fd in select(readable, [], [])[0]:
            data = os.read(fd, 1024) # read available
            if not data: # EOF
                del readable[fd]
            else:
                st.write(data.decode("utf-8"))
                readable[fd].write(data)
                readable[fd].flush()                   

## 
def get_out_files(path='.'):
    """Recursive function to find all files in given directory path."""
    files = []
    for item in os.listdir(path):
        fp = os.path.join(path, item)
        if os.path.isdir(fp):
            files.append(fp)
            files += get_out_files(fp)
        else:
            if fp.endswith(".test"):
                files.append(fp)
                #st.write(fp)
            else:
                #st.write("skip"+fp)
                pass
    return files


if st.button(f"Scan output {input_dir}"):
    st.write('Going to scan')
    outfiles = get_out_files(input_dir)
    if len(outfiles) > limit:
        outfiles = outfiles[0:limit]
        #st.write(outfiles)

        for x in outfiles:
            if os.path.isdir(x):
                pass
            else:
                (p,f) =os.path.split(x)
                with open(x, "r") as fp:
                    btn = st.download_button(
                        label="Download text" + f,
                        data=fp,
                        file_name=f,
                        mime="application/text"
                    )

                    ###

                    def get_out_files(path='.'):
    """Recursive function to find all files in given directory path."""
    files = []
    for item in os.listdir(path):
        fp = os.path.join(path, item)
        if os.path.isdir(fp):
            files.append(fp)
            files += get_out_files(fp)
        else:
            if fp.endswith(".test"):
                files.append(fp)
                #st.write(fp)
            else:
                #st.write("skip"+fp)
                pass
    return files


if st.button(f"Scan output {input_dir}"):
    st.write('Going to scan')
    outfiles = get_out_files(input_dir)
    if len(outfiles) > limit:
        outfiles = outfiles[0:limit]
        #st.write(outfiles)

        for x in outfiles:
            if os.path.isdir(x):
                pass
            else:
                (p,f) =os.path.split(x)
                with open(x, "r") as fp:
                    btn = st.download_button(
                        label="Download text" + f,
                        data=fp,
                        file_name=f,
                        mime="application/text"
                    )