Spaces:
				
			
			
	
			
			
		Paused
		
	
	
	
			
			
	
	
	
	
		
		
		Paused
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1358,8 +1358,7 @@ def create_free_form_generation_demo(): | |
| 1358 | 
             
                presence_penalty = PRESENCE_PENALTY
         | 
| 1359 |  | 
| 1360 | 
             
                introduction = """
         | 
| 1361 | 
            -
             | 
| 1362 | 
            -
            Put any context string (like few-shot prompts) and get the model to generate.
         | 
| 1363 | 
             
                """
         | 
| 1364 |  | 
| 1365 | 
             
                with gr.Blocks() as demo_free_form:
         | 
| @@ -1391,6 +1390,78 @@ Put any context string (like few-shot prompts) and get the model to generate. | |
| 1391 |  | 
| 1392 |  | 
| 1393 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1394 |  | 
| 1395 |  | 
| 1396 | 
             
            def launch_demo():
         | 
| @@ -1486,64 +1557,11 @@ def launch_demo(): | |
| 1486 |  | 
| 1487 | 
             
                if ENABLE_BATCH_INFER:
         | 
| 1488 |  | 
| 1489 | 
            -
                    demo_file_upload =  | 
| 1490 | 
            -
                        batch_inference,
         | 
| 1491 | 
            -
                        inputs=[
         | 
| 1492 | 
            -
                            gr.File(file_count='single', file_types=['json']),
         | 
| 1493 | 
            -
                            gr.Radio(["chat", "few-shot"], value='chat', label="Chat or Few-shot mode", info="Chat's output more user-friendly, Few-shot's output more consistent with few-shot patterns."),
         | 
| 1494 | 
            -
                            gr.Number(value=temperature, label='Temperature', info="Higher -> more random"), 
         | 
| 1495 | 
            -
                            gr.Number(value=max_tokens, label='Max tokens', info='Increase if want more generation'), 
         | 
| 1496 | 
            -
                            gr.Number(value=frequence_penalty, label='Frequency penalty', info='> 0 encourage new tokens over repeated tokens'), 
         | 
| 1497 | 
            -
                            gr.Number(value=presence_penalty, label='Presence penalty', info='> 0 encourage new tokens, < 0 encourage existing tokens'), 
         | 
| 1498 | 
            -
                            gr.Textbox(value="<s>,</s>,<|im_start|>", label='Stop strings', info='Comma-separated string to stop generation only in FEW-SHOT mode', lines=1),
         | 
| 1499 | 
            -
                            gr.Number(value=0, label='current_time', visible=False), 
         | 
| 1500 | 
            -
                        ],
         | 
| 1501 | 
            -
                        outputs=[
         | 
| 1502 | 
            -
                            # "file",
         | 
| 1503 | 
            -
                            gr.File(label="Generated file"),
         | 
| 1504 | 
            -
                            # "json"
         | 
| 1505 | 
            -
                            gr.JSON(label='Example outputs (display 2 samples)')
         | 
| 1506 | 
            -
                        ],
         | 
| 1507 | 
            -
                        description=FILE_UPLOAD_DESCRIPTION,
         | 
| 1508 | 
            -
                        allow_flagging=False,
         | 
| 1509 | 
            -
                        examples=[
         | 
| 1510 | 
            -
                            ["upload_chat.json", "chat", 0.2, 1024, 0.5, 0, "<s>,</s>,<|im_start|>"],
         | 
| 1511 | 
            -
                            ["upload_few_shot.json", "few-shot", 0.2, 128, 0.5, 0, "<s>,</s>,<|im_start|>,\\n"]
         | 
| 1512 | 
            -
                        ],
         | 
| 1513 | 
            -
                        cache_examples=False,
         | 
| 1514 | 
            -
                    )
         | 
| 1515 |  | 
| 1516 | 
             
                    demo_free_form = create_free_form_generation_demo()
         | 
| 1517 |  | 
| 1518 | 
            -
                    demo_chat =  | 
| 1519 | 
            -
                        response_fn,
         | 
| 1520 | 
            -
                        chatbot=ChatBot(
         | 
| 1521 | 
            -
                            label=MODEL_NAME,
         | 
| 1522 | 
            -
                            bubble_full_width=False,
         | 
| 1523 | 
            -
                            latex_delimiters=[
         | 
| 1524 | 
            -
                                { "left": "$", "right": "$", "display": False},
         | 
| 1525 | 
            -
                                { "left": "$$", "right": "$$", "display": True},
         | 
| 1526 | 
            -
                            ],
         | 
| 1527 | 
            -
                            show_copy_button=True,
         | 
| 1528 | 
            -
                        ),
         | 
| 1529 | 
            -
                        textbox=gr.Textbox(placeholder='Type message', lines=4, max_lines=128, min_width=200),
         | 
| 1530 | 
            -
                        submit_btn=gr.Button(value='Submit', variant="primary", scale=0),
         | 
| 1531 | 
            -
                        # ! consider preventing the stop button
         | 
| 1532 | 
            -
                        # stop_btn=None,
         | 
| 1533 | 
            -
                        # title=f"{model_title}",
         | 
| 1534 | 
            -
                        # description=f"{model_desc}",
         | 
| 1535 | 
            -
                        additional_inputs=[
         | 
| 1536 | 
            -
                            gr.Number(value=temperature, label='Temperature (higher -> more random)'), 
         | 
| 1537 | 
            -
                            gr.Number(value=max_tokens, label='Max generated tokens (increase if want more generation)'), 
         | 
| 1538 | 
            -
                            gr.Number(value=frequence_penalty, label='Frequency penalty (> 0 encourage new tokens over repeated tokens)'), 
         | 
| 1539 | 
            -
                            gr.Number(value=presence_penalty, label='Presence penalty (> 0 encourage new tokens, < 0 encourage existing tokens)'), 
         | 
| 1540 | 
            -
                            gr.Number(value=0, label='current_time', visible=False), 
         | 
| 1541 | 
            -
                            # ! Remove the system prompt textbox to avoid jailbreaking
         | 
| 1542 | 
            -
                            # gr.Textbox(value=sys_prompt, label='System prompt', lines=8)
         | 
| 1543 | 
            -
                        ], 
         | 
| 1544 | 
            -
                        examples=CHAT_EXAMPLES,
         | 
| 1545 | 
            -
                        cache_examples=False
         | 
| 1546 | 
            -
                    )
         | 
| 1547 | 
             
                    descriptions = model_desc
         | 
| 1548 | 
             
                    if DISPLAY_MODEL_PATH:
         | 
| 1549 | 
             
                        descriptions += f"<br> {path_markdown.format(model_path=model_path)}"
         | 
| @@ -1554,80 +1572,33 @@ def launch_demo(): | |
| 1554 | 
             
                        title=f"{model_title}",
         | 
| 1555 | 
             
                        description=descriptions,
         | 
| 1556 | 
             
                    )
         | 
| 1557 | 
            -
                    demo.title = MODEL_NAME
         | 
| 1558 | 
            -
                    callback = None
         | 
| 1559 | 
            -
                    with demo:
         | 
| 1560 | 
            -
                        if DATA_SET_REPO_PATH != "":
         | 
| 1561 | 
            -
                            try:
         | 
| 1562 | 
            -
                                from performance_plot import attach_plot_to_demo
         | 
| 1563 | 
            -
                                attach_plot_to_demo(demo)
         | 
| 1564 | 
            -
                            except Exception as e:
         | 
| 1565 | 
            -
                                print(f'Fail to load DEMO plot: {str(e)}')
         | 
| 1566 | 
            -
                        
         | 
| 1567 | 
            -
                        gr.Markdown(cite_markdown)
         | 
| 1568 | 
            -
                        # if DISPLAY_MODEL_PATH:
         | 
| 1569 | 
            -
                        #     gr.Markdown(path_markdown.format(model_path=model_path))
         | 
| 1570 | 
            -
                        
         | 
| 1571 | 
            -
                        if ENABLE_AGREE_POPUP:
         | 
| 1572 | 
            -
                            demo.load(None, None, None, _js=AGREE_POP_SCRIPTS)
         | 
| 1573 | 
            -
                    
         | 
| 1574 | 
            -
                    demo.queue(api_open=False)
         | 
| 1575 | 
            -
                    # demo.launch(server_port=PORT, show_api=False, allowed_paths=["seal_logo.png"])
         | 
| 1576 | 
            -
                    # demo.launch(show_api=False, allowed_paths=["seal_logo.png"])
         | 
| 1577 | 
             
                else:
         | 
| 1578 | 
             
                    descriptions = model_desc
         | 
| 1579 | 
             
                    if DISPLAY_MODEL_PATH:
         | 
| 1580 | 
             
                        descriptions += f"<br> {path_markdown.format(model_path=model_path)}"
         | 
| 1581 | 
            -
             | 
| 1582 | 
            -
             | 
| 1583 | 
            -
             | 
| 1584 | 
            -
             | 
| 1585 | 
            -
             | 
| 1586 | 
            -
             | 
| 1587 | 
            -
             | 
| 1588 | 
            -
             | 
| 1589 | 
            -
                             | 
| 1590 | 
            -
             | 
| 1591 | 
            -
             | 
| 1592 | 
            -
                        textbox=gr.Textbox(placeholder='Type message', lines=4, max_lines=128, min_width=200),
         | 
| 1593 | 
            -
                        submit_btn=gr.Button(value='Submit', variant="primary", scale=0),
         | 
| 1594 | 
            -
                        # ! consider preventing the stop button
         | 
| 1595 | 
            -
                        # stop_btn=None,
         | 
| 1596 | 
            -
                        title=f"{model_title}",
         | 
| 1597 | 
            -
                        description=descriptions,
         | 
| 1598 | 
            -
                        additional_inputs=[
         | 
| 1599 | 
            -
                            gr.Number(value=temperature, label='Temperature (higher -> more random)'), 
         | 
| 1600 | 
            -
                            gr.Number(value=max_tokens, label='Max generated tokens (increase if want more generation)'), 
         | 
| 1601 | 
            -
                            gr.Number(value=frequence_penalty, label='Frequency penalty (> 0 encourage new tokens over repeated tokens)'), 
         | 
| 1602 | 
            -
                            gr.Number(value=presence_penalty, label='Presence penalty (> 0 encourage new tokens, < 0 encourage existing tokens)'), 
         | 
| 1603 | 
            -
                            gr.Number(value=0, label='current_time', visible=False), 
         | 
| 1604 | 
            -
                            # ! Remove the system prompt textbox to avoid jailbreaking
         | 
| 1605 | 
            -
                            # gr.Textbox(value=sys_prompt, label='System prompt', lines=8)
         | 
| 1606 | 
            -
                        ], 
         | 
| 1607 | 
            -
                        examples=CHAT_EXAMPLES,
         | 
| 1608 | 
            -
                        cache_examples=False
         | 
| 1609 | 
            -
                    )
         | 
| 1610 | 
            -
                    demo.title = MODEL_NAME
         | 
| 1611 | 
            -
                    with demo:
         | 
| 1612 | 
            -
                        gr.Markdown(cite_markdown)
         | 
| 1613 | 
            -
                        if DISPLAY_MODEL_PATH:
         | 
| 1614 | 
            -
                            gr.Markdown(path_markdown.format(model_path=model_path))
         | 
| 1615 | 
            -
                        
         | 
| 1616 | 
            -
                        if ENABLE_AGREE_POPUP:
         | 
| 1617 | 
            -
                            demo.load(None, None, None, _js=AGREE_POP_SCRIPTS)
         | 
| 1618 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1619 |  | 
| 1620 | 
            -
             | 
| 1621 | 
            -
                    #demo.launch(server_port=PORT, show_api=False, allowed_paths=["seal_logo.png"])
         | 
| 1622 | 
            -
                # demo.launch(show_api=False, allowed_paths=["seal_logo.png"])
         | 
| 1623 | 
             
                return demo
         | 
| 1624 |  | 
| 1625 |  | 
| 1626 | 
            -
            # def main():
         | 
| 1627 | 
            -
             | 
| 1628 | 
            -
            #     launch()
         | 
| 1629 | 
            -
             | 
| 1630 | 
            -
             | 
| 1631 | 
             
            if __name__ == "__main__":
         | 
| 1632 | 
             
                demo = launch_demo()
         | 
| 1633 | 
             
                demo.launch(show_api=False, allowed_paths=["seal_logo.png"])
         | 
|  | |
| 1358 | 
             
                presence_penalty = PRESENCE_PENALTY
         | 
| 1359 |  | 
| 1360 | 
             
                introduction = """
         | 
| 1361 | 
            +
            ### Free-form | Put any context string (like few-shot prompts)
         | 
|  | |
| 1362 | 
             
                """
         | 
| 1363 |  | 
| 1364 | 
             
                with gr.Blocks() as demo_free_form:
         | 
|  | |
| 1390 |  | 
| 1391 |  | 
| 1392 |  | 
| 1393 | 
            +
            def create_file_upload_demo():
         | 
| 1394 | 
            +
                temperature = TEMPERATURE
         | 
| 1395 | 
            +
                frequence_penalty = FREQUENCE_PENALTY
         | 
| 1396 | 
            +
                presence_penalty = PRESENCE_PENALTY
         | 
| 1397 | 
            +
                max_tokens = MAX_TOKENS
         | 
| 1398 | 
            +
                demo_file_upload = gr.Interface(
         | 
| 1399 | 
            +
                    batch_inference,
         | 
| 1400 | 
            +
                    inputs=[
         | 
| 1401 | 
            +
                        gr.File(file_count='single', file_types=['json']),
         | 
| 1402 | 
            +
                        gr.Radio(["chat", "few-shot"], value='chat', label="Chat or Few-shot mode", info="Chat's output more user-friendly, Few-shot's output more consistent with few-shot patterns."),
         | 
| 1403 | 
            +
                        gr.Number(value=temperature, label='Temperature', info="Higher -> more random"), 
         | 
| 1404 | 
            +
                        gr.Number(value=max_tokens, label='Max tokens', info='Increase if want more generation'), 
         | 
| 1405 | 
            +
                        gr.Number(value=frequence_penalty, label='Frequency penalty', info='> 0 encourage new tokens over repeated tokens'), 
         | 
| 1406 | 
            +
                        gr.Number(value=presence_penalty, label='Presence penalty', info='> 0 encourage new tokens, < 0 encourage existing tokens'), 
         | 
| 1407 | 
            +
                        gr.Textbox(value="<s>,</s>,<|im_start|>", label='Stop strings', info='Comma-separated string to stop generation only in FEW-SHOT mode', lines=1),
         | 
| 1408 | 
            +
                        gr.Number(value=0, label='current_time', visible=False), 
         | 
| 1409 | 
            +
                    ],
         | 
| 1410 | 
            +
                    outputs=[
         | 
| 1411 | 
            +
                        # "file",
         | 
| 1412 | 
            +
                        gr.File(label="Generated file"),
         | 
| 1413 | 
            +
                        # "json"
         | 
| 1414 | 
            +
                        gr.JSON(label='Example outputs (display 2 samples)')
         | 
| 1415 | 
            +
                    ],
         | 
| 1416 | 
            +
                    description=FILE_UPLOAD_DESCRIPTION,
         | 
| 1417 | 
            +
                    allow_flagging=False,
         | 
| 1418 | 
            +
                    examples=[
         | 
| 1419 | 
            +
                        ["upload_chat.json", "chat", 0.2, 1024, 0.5, 0, "<s>,</s>,<|im_start|>"],
         | 
| 1420 | 
            +
                        ["upload_few_shot.json", "few-shot", 0.2, 128, 0.5, 0, "<s>,</s>,<|im_start|>,\\n"]
         | 
| 1421 | 
            +
                    ],
         | 
| 1422 | 
            +
                    cache_examples=False,
         | 
| 1423 | 
            +
                )
         | 
| 1424 | 
            +
                return demo_file_upload
         | 
| 1425 | 
            +
             | 
| 1426 | 
            +
             | 
| 1427 | 
            +
            def create_chat_demo(title=None, description=None):
         | 
| 1428 | 
            +
                sys_prompt = SYSTEM_PROMPT_1
         | 
| 1429 | 
            +
                max_tokens = MAX_TOKENS
         | 
| 1430 | 
            +
                temperature = TEMPERATURE
         | 
| 1431 | 
            +
                frequence_penalty = FREQUENCE_PENALTY
         | 
| 1432 | 
            +
                presence_penalty = PRESENCE_PENALTY
         | 
| 1433 | 
            +
             | 
| 1434 | 
            +
                demo_chat = gr.ChatInterface(
         | 
| 1435 | 
            +
                    chat_response_stream_multiturn,
         | 
| 1436 | 
            +
                    chatbot=ChatBot(
         | 
| 1437 | 
            +
                        label=MODEL_NAME,
         | 
| 1438 | 
            +
                        bubble_full_width=False,
         | 
| 1439 | 
            +
                        latex_delimiters=[
         | 
| 1440 | 
            +
                            { "left": "$", "right": "$", "display": False},
         | 
| 1441 | 
            +
                            { "left": "$$", "right": "$$", "display": True},
         | 
| 1442 | 
            +
                        ],
         | 
| 1443 | 
            +
                        show_copy_button=True,
         | 
| 1444 | 
            +
                    ),
         | 
| 1445 | 
            +
                    textbox=gr.Textbox(placeholder='Type message', lines=4, max_lines=128, min_width=200),
         | 
| 1446 | 
            +
                    submit_btn=gr.Button(value='Submit', variant="primary", scale=0),
         | 
| 1447 | 
            +
                    # ! consider preventing the stop button
         | 
| 1448 | 
            +
                    # stop_btn=None,
         | 
| 1449 | 
            +
                    title=title,
         | 
| 1450 | 
            +
                    description=description,
         | 
| 1451 | 
            +
                    additional_inputs=[
         | 
| 1452 | 
            +
                        gr.Number(value=temperature, label='Temperature (higher -> more random)'), 
         | 
| 1453 | 
            +
                        gr.Number(value=max_tokens, label='Max generated tokens (increase if want more generation)'), 
         | 
| 1454 | 
            +
                        gr.Number(value=frequence_penalty, label='Frequency penalty (> 0 encourage new tokens over repeated tokens)'), 
         | 
| 1455 | 
            +
                        gr.Number(value=presence_penalty, label='Presence penalty (> 0 encourage new tokens, < 0 encourage existing tokens)'), 
         | 
| 1456 | 
            +
                        gr.Number(value=0, label='current_time', visible=False), 
         | 
| 1457 | 
            +
                        # ! Remove the system prompt textbox to avoid jailbreaking
         | 
| 1458 | 
            +
                        gr.Textbox(value=sys_prompt, label='System prompt', lines=8, interactive=False)
         | 
| 1459 | 
            +
                    ], 
         | 
| 1460 | 
            +
                    examples=CHAT_EXAMPLES,
         | 
| 1461 | 
            +
                    cache_examples=False
         | 
| 1462 | 
            +
                )
         | 
| 1463 | 
            +
                return demo_chat
         | 
| 1464 | 
            +
             | 
| 1465 |  | 
| 1466 |  | 
| 1467 | 
             
            def launch_demo():
         | 
|  | |
| 1557 |  | 
| 1558 | 
             
                if ENABLE_BATCH_INFER:
         | 
| 1559 |  | 
| 1560 | 
            +
                    demo_file_upload = create_file_upload_demo()
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1561 |  | 
| 1562 | 
             
                    demo_free_form = create_free_form_generation_demo()
         | 
| 1563 |  | 
| 1564 | 
            +
                    demo_chat = create_chat_demo()
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1565 | 
             
                    descriptions = model_desc
         | 
| 1566 | 
             
                    if DISPLAY_MODEL_PATH:
         | 
| 1567 | 
             
                        descriptions += f"<br> {path_markdown.format(model_path=model_path)}"
         | 
|  | |
| 1572 | 
             
                        title=f"{model_title}",
         | 
| 1573 | 
             
                        description=descriptions,
         | 
| 1574 | 
             
                    )
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1575 | 
             
                else:
         | 
| 1576 | 
             
                    descriptions = model_desc
         | 
| 1577 | 
             
                    if DISPLAY_MODEL_PATH:
         | 
| 1578 | 
             
                        descriptions += f"<br> {path_markdown.format(model_path=model_path)}"
         | 
| 1579 | 
            +
             | 
| 1580 | 
            +
                    demo = create_chat_demo(title=f"{model_title}", description=descriptions)
         | 
| 1581 | 
            +
                demo.title = MODEL_NAME
         | 
| 1582 | 
            +
                
         | 
| 1583 | 
            +
                with demo:
         | 
| 1584 | 
            +
                    if DATA_SET_REPO_PATH != "":
         | 
| 1585 | 
            +
                        try:
         | 
| 1586 | 
            +
                            from performance_plot import attach_plot_to_demo
         | 
| 1587 | 
            +
                            attach_plot_to_demo(demo)
         | 
| 1588 | 
            +
                        except Exception as e:
         | 
| 1589 | 
            +
                            print(f'Fail to load DEMO plot: {str(e)}')
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1590 |  | 
| 1591 | 
            +
                    gr.Markdown(cite_markdown)
         | 
| 1592 | 
            +
                    if DISPLAY_MODEL_PATH:
         | 
| 1593 | 
            +
                        gr.Markdown(path_markdown.format(model_path=model_path))
         | 
| 1594 | 
            +
                    
         | 
| 1595 | 
            +
                    if ENABLE_AGREE_POPUP:
         | 
| 1596 | 
            +
                        demo.load(None, None, None, _js=AGREE_POP_SCRIPTS)
         | 
| 1597 |  | 
| 1598 | 
            +
                demo.queue(api_open=False)
         | 
|  | |
|  | |
| 1599 | 
             
                return demo
         | 
| 1600 |  | 
| 1601 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
| 1602 | 
             
            if __name__ == "__main__":
         | 
| 1603 | 
             
                demo = launch_demo()
         | 
| 1604 | 
             
                demo.launch(show_api=False, allowed_paths=["seal_logo.png"])
         | 
