Spaces:
				
			
			
	
			
			
		Build error
		
	
	
	
			
			
	
	
	
	
		
		
		Build error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -191,9 +191,52 @@ def run_gpt( | |
| 191 | 
             
                    print(LOG_RESPONSE.format(resp))
         | 
| 192 | 
             
                return resp
         | 
| 193 |  | 
|  | |
| 194 | 
             
            def compress_data(c, instruct, history):
         | 
| 195 | 
             
                seed=random.randint(1,1000000000)
         | 
| 196 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 197 | 
             
                print (c)
         | 
| 198 | 
             
                #tot=len(purpose)
         | 
| 199 | 
             
                #print(tot)
         | 
| @@ -224,6 +267,7 @@ def compress_data(c, instruct, history): | |
| 224 | 
             
                        knowledge=new_history,
         | 
| 225 | 
             
                        history=hist,
         | 
| 226 | 
             
                    )
         | 
|  | |
| 227 | 
             
                    new_history = resp
         | 
| 228 | 
             
                    print (resp)
         | 
| 229 | 
             
                    out+=resp
         | 
| @@ -308,7 +352,16 @@ def summarize(inp,history,data=None,files=None,url=None,pdf_url=None,pdf_batch=N | |
| 308 | 
             
                            c +=1
         | 
| 309 | 
             
                    print (f'c:: {c}')
         | 
| 310 |  | 
| 311 | 
            -
                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 312 | 
             
                else:
         | 
| 313 | 
             
                    rawp = "Provide a valid data source"
         | 
| 314 | 
             
                #print (rawp)
         | 
| @@ -317,7 +370,7 @@ def summarize(inp,history,data=None,files=None,url=None,pdf_url=None,pdf_batch=N | |
| 317 | 
             
                #task = "complete?"
         | 
| 318 | 
             
                history.clear()
         | 
| 319 | 
             
                history.append((inp,rawp))
         | 
| 320 | 
            -
                yield "", history,error_box | 
| 321 |  | 
| 322 | 
             
            #################################
         | 
| 323 | 
             
            def clear_fn():
         | 
| @@ -347,10 +400,11 @@ with gr.Blocks() as app: | |
| 347 | 
             
                        pdf_url = gr.Textbox(label="PDF URL")       
         | 
| 348 | 
             
                    with gr.Tab("PDF Batch"):
         | 
| 349 | 
             
                        pdf_batch = gr.Textbox(label="PDF Batch (comma separated)")
         | 
|  | |
| 350 | 
             
                e_box=gr.Textbox()
         | 
| 351 | 
             
                #text=gr.JSON()
         | 
| 352 | 
             
                #inp_query.change(search_models,inp_query,models_dd)
         | 
| 353 | 
             
                clear_btn.click(clear_fn,None,[prompt,chatbot])
         | 
| 354 | 
            -
                go=button.click(summarize,[prompt,chatbot,data,file,url,pdf_url,pdf_batch],[prompt,chatbot,e_box])
         | 
| 355 | 
             
                stop_button.click(None,None,None,cancels=[go])
         | 
| 356 | 
             
            app.launch(server_port=7860,show_api=False) 
         | 
|  | |
| 191 | 
             
                    print(LOG_RESPONSE.format(resp))
         | 
| 192 | 
             
                return resp
         | 
| 193 |  | 
| 194 | 
            +
                
         | 
| 195 | 
             
            def compress_data(c, instruct, history):
         | 
| 196 | 
             
                seed=random.randint(1,1000000000)
         | 
| 197 |  | 
| 198 | 
            +
                print (c)
         | 
| 199 | 
            +
                #tot=len(purpose)
         | 
| 200 | 
            +
                #print(tot)
         | 
| 201 | 
            +
                divr=int(c)/MAX_DATA
         | 
| 202 | 
            +
                divi=int(divr)+1 if divr != int(divr) else int(divr)
         | 
| 203 | 
            +
                chunk = int(int(c)/divr)
         | 
| 204 | 
            +
                print(f'chunk:: {chunk}')
         | 
| 205 | 
            +
                print(f'divr:: {divr}')
         | 
| 206 | 
            +
                print (f'divi:: {divi}')
         | 
| 207 | 
            +
                out = []
         | 
| 208 | 
            +
                #out=""
         | 
| 209 | 
            +
                s=0
         | 
| 210 | 
            +
                e=chunk
         | 
| 211 | 
            +
                print(f'e:: {e}')
         | 
| 212 | 
            +
                new_history=""
         | 
| 213 | 
            +
                #task = f'Compile this data to fulfill the task: {task}, and complete the purpose: {purpose}\n'
         | 
| 214 | 
            +
                for z in range(divi):
         | 
| 215 | 
            +
                    print(f's:e :: {s}:{e}')
         | 
| 216 | 
            +
                    
         | 
| 217 | 
            +
                    hist = history[s:e]
         | 
| 218 | 
            +
                    
         | 
| 219 | 
            +
                    resp = run_gpt(
         | 
| 220 | 
            +
                        COMPRESS_DATA_PROMPT_SMALL,
         | 
| 221 | 
            +
                        stop_tokens=["observation:", "task:", "action:", "thought:"],
         | 
| 222 | 
            +
                        max_tokens=8192,
         | 
| 223 | 
            +
                        seed=seed,
         | 
| 224 | 
            +
                        direction=instruct,
         | 
| 225 | 
            +
                        knowledge="",
         | 
| 226 | 
            +
                        history=hist,
         | 
| 227 | 
            +
                    )
         | 
| 228 | 
            +
                    out.append(resp)
         | 
| 229 | 
            +
                    new_history = resp
         | 
| 230 | 
            +
                    print (resp)
         | 
| 231 | 
            +
                    out+=resp
         | 
| 232 | 
            +
                    e=e+chunk
         | 
| 233 | 
            +
                    s=s+chunk
         | 
| 234 | 
            +
                return out
         | 
| 235 | 
            +
             | 
| 236 | 
            +
                
         | 
| 237 | 
            +
            def compress_data_og(c, instruct, history):
         | 
| 238 | 
            +
                seed=random.randint(1,1000000000)
         | 
| 239 | 
            +
                
         | 
| 240 | 
             
                print (c)
         | 
| 241 | 
             
                #tot=len(purpose)
         | 
| 242 | 
             
                #print(tot)
         | 
|  | |
| 267 | 
             
                        knowledge=new_history,
         | 
| 268 | 
             
                        history=hist,
         | 
| 269 | 
             
                    )
         | 
| 270 | 
            +
                    
         | 
| 271 | 
             
                    new_history = resp
         | 
| 272 | 
             
                    print (resp)
         | 
| 273 | 
             
                    out+=resp
         | 
|  | |
| 352 | 
             
                            c +=1
         | 
| 353 | 
             
                    print (f'c:: {c}')
         | 
| 354 |  | 
| 355 | 
            +
                    json_out = compress_data(c,inp,out)    
         | 
| 356 | 
            +
                    out = str(json_out)
         | 
| 357 | 
            +
                    rl = len(out)
         | 
| 358 | 
            +
                    print(f'rl:: {rl}')
         | 
| 359 | 
            +
                    c=1
         | 
| 360 | 
            +
                    for i in str(out):
         | 
| 361 | 
            +
                        if i == " " or i=="," or i=="\n":
         | 
| 362 | 
            +
                            c +=1
         | 
| 363 | 
            +
                    print (f'c2:: {c}')
         | 
| 364 | 
            +
                    rawp = compress_data(c,inp,out)
         | 
| 365 | 
             
                else:
         | 
| 366 | 
             
                    rawp = "Provide a valid data source"
         | 
| 367 | 
             
                #print (rawp)
         | 
|  | |
| 370 | 
             
                #task = "complete?"
         | 
| 371 | 
             
                history.clear()
         | 
| 372 | 
             
                history.append((inp,rawp))
         | 
| 373 | 
            +
                yield "", history,error_box,json_out    
         | 
| 374 |  | 
| 375 | 
             
            #################################
         | 
| 376 | 
             
            def clear_fn():
         | 
|  | |
| 400 | 
             
                        pdf_url = gr.Textbox(label="PDF URL")       
         | 
| 401 | 
             
                    with gr.Tab("PDF Batch"):
         | 
| 402 | 
             
                        pdf_batch = gr.Textbox(label="PDF Batch (comma separated)")
         | 
| 403 | 
            +
                json_out=gr.JSON()
         | 
| 404 | 
             
                e_box=gr.Textbox()
         | 
| 405 | 
             
                #text=gr.JSON()
         | 
| 406 | 
             
                #inp_query.change(search_models,inp_query,models_dd)
         | 
| 407 | 
             
                clear_btn.click(clear_fn,None,[prompt,chatbot])
         | 
| 408 | 
            +
                go=button.click(summarize,[prompt,chatbot,data,file,url,pdf_url,pdf_batch],[prompt,chatbot,e_box,json_out])
         | 
| 409 | 
             
                stop_button.click(None,None,None,cancels=[go])
         | 
| 410 | 
             
            app.launch(server_port=7860,show_api=False) 
         | 
 
			
