Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,6 +106,7 @@ def generate(prompt,history,mod=2,tok=4000,seed=1,role="ASSISTANT",data=None):
|
|
| 106 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
| 107 |
for response in stream:
|
| 108 |
output += response.token.text
|
|
|
|
| 109 |
#print(file_content)
|
| 110 |
print(output)
|
| 111 |
yield 'test1'
|
|
@@ -129,7 +130,34 @@ def generate(prompt,history,mod=2,tok=4000,seed=1,role="ASSISTANT",data=None):
|
|
| 129 |
image_out.save(output)
|
| 130 |
print('Done: ',output)
|
| 131 |
return [{'role':'assistant','content': {'path':output}}]'''
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
def build_space(repo_name,file_name,file_content,access_token=""):
|
| 134 |
try:
|
| 135 |
repo_path="broadfield/"+repo_name
|
|
@@ -143,6 +171,7 @@ def build_space(repo_name,file_name,file_content,access_token=""):
|
|
| 143 |
exist_ok=True,
|
| 144 |
private=False,
|
| 145 |
)
|
|
|
|
| 146 |
# Create a new Space
|
| 147 |
#response = api.create_repo(repo_path)
|
| 148 |
#space_info = repo_url.json()
|
|
@@ -212,6 +241,7 @@ def agent(prompt_in,history,mod=2):
|
|
| 212 |
in_data[1]=com
|
| 213 |
out_o =generate(prompt,history,mod=mod,tok=10000,seed=seed,role="CREATE_FILE",data=in_data)
|
| 214 |
out_w=list(out_o)
|
|
|
|
| 215 |
build_space(out_w[0],out_w[1],out_w[2])
|
| 216 |
elif 'IMAGE' in fn:
|
| 217 |
print('IMAGE called')
|
|
@@ -226,8 +256,8 @@ def agent(prompt_in,history,mod=2):
|
|
| 226 |
elif 'NONE' in fn:
|
| 227 |
print('ERROR ACTION NOT FOUND')
|
| 228 |
history+=[{'role':'system','content':f'observation:The last thing we attempted resulted in an error, check formatting on the tool call'}]
|
| 229 |
-
|
| 230 |
else:pass;seed = random.randint(1,9999999999999)
|
|
|
|
| 231 |
with gr.Blocks() as ux:
|
| 232 |
with gr.Row():
|
| 233 |
with gr.Column():
|
|
|
|
| 106 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
| 107 |
for response in stream:
|
| 108 |
output += response.token.text
|
| 109 |
+
|
| 110 |
#print(file_content)
|
| 111 |
print(output)
|
| 112 |
yield 'test1'
|
|
|
|
| 130 |
image_out.save(output)
|
| 131 |
print('Done: ',output)
|
| 132 |
return [{'role':'assistant','content': {'path':output}}]'''
|
| 133 |
+
def parse_json(inp):
|
| 134 |
+
if type(inp)==type(""):
|
| 135 |
+
if "```" in inp:
|
| 136 |
+
tog=False
|
| 137 |
+
cnt=0
|
| 138 |
+
lines=""
|
| 139 |
+
for line in inp.split("\n"):
|
| 140 |
+
if "```" in line:
|
| 141 |
+
cnt+=1
|
| 142 |
+
if cnt==1:
|
| 143 |
+
tog = True
|
| 144 |
+
elif cnt==2:
|
| 145 |
+
tog = False
|
| 146 |
+
if tog==True:
|
| 147 |
+
lines+=line
|
| 148 |
+
try:
|
| 149 |
+
print(lines)
|
| 150 |
+
out_json=eval(lines)
|
| 151 |
+
out1=out_json['filename']
|
| 152 |
+
out2=out_json['filecontent']
|
| 153 |
+
return out1,out2
|
| 154 |
+
except Exception as e:
|
| 155 |
+
print(e)
|
| 156 |
+
return "None","None"
|
| 157 |
+
elif type(inp)==type({}):
|
| 158 |
+
out1=inp['filename']
|
| 159 |
+
out2=inp['filecontent']
|
| 160 |
+
return out1,out2
|
| 161 |
def build_space(repo_name,file_name,file_content,access_token=""):
|
| 162 |
try:
|
| 163 |
repo_path="broadfield/"+repo_name
|
|
|
|
| 171 |
exist_ok=True,
|
| 172 |
private=False,
|
| 173 |
)
|
| 174 |
+
|
| 175 |
# Create a new Space
|
| 176 |
#response = api.create_repo(repo_path)
|
| 177 |
#space_info = repo_url.json()
|
|
|
|
| 241 |
in_data[1]=com
|
| 242 |
out_o =generate(prompt,history,mod=mod,tok=10000,seed=seed,role="CREATE_FILE",data=in_data)
|
| 243 |
out_w=list(out_o)
|
| 244 |
+
ret1,ret2 = parse_json(out_w[2])
|
| 245 |
build_space(out_w[0],out_w[1],out_w[2])
|
| 246 |
elif 'IMAGE' in fn:
|
| 247 |
print('IMAGE called')
|
|
|
|
| 256 |
elif 'NONE' in fn:
|
| 257 |
print('ERROR ACTION NOT FOUND')
|
| 258 |
history+=[{'role':'system','content':f'observation:The last thing we attempted resulted in an error, check formatting on the tool call'}]
|
|
|
|
| 259 |
else:pass;seed = random.randint(1,9999999999999)
|
| 260 |
+
|
| 261 |
with gr.Blocks() as ux:
|
| 262 |
with gr.Row():
|
| 263 |
with gr.Column():
|