Spaces:
Sleeping
Sleeping
File size: 32,048 Bytes
cdeb7b2 1d6a862 cdeb7b2 1d6a862 81c9675 cdeb7b2 1d6a862 61c92f4 807b3b1 61c92f4 807b3b1 61c92f4 807b3b1 61c92f4 807b3b1 61c92f4 807b3b1 81c9675 6bba7ce 81c9675 6bba7ce 81c9675 1d6a862 4bca50c cdeb7b2 4bca50c b26952f 0d9856e 4bca50c 7acded7 81c9675 7acded7 81c9675 b26952f 7acded7 81c9675 0d9856e 1d6a862 0d9856e 81c9675 6bba7ce 81c9675 0d9856e 81c9675 0d9856e cdeb7b2 81c9675 cdeb7b2 4bca50c 1d6a862 0d9856e 81c9675 7d70c7e 81c9675 6bba7ce 81c9675 0d9856e 1d6a862 |
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 |
import gradio as gr
from gradio_client import Client, handle_file
import os
# Define your Hugging Face token (make sure to set it as an environment variable)
HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
# Initialize the Gradio Client for the specified API
client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
# Function to handle chat API call
def stream_chat_with_rag(
message: str,
history: list,
client_name: str,
system_prompt: str,
num_retrieved_docs: int,
num_docs_final: int,
temperature: float,
max_new_tokens: int,
top_p: float,
top_k: int,
penalty: float,
):
# Use the parameters provided by the UI
response = client.predict(
message=message,
client_name=client_name,
system_prompt=system_prompt,
num_retrieved_docs=num_retrieved_docs,
num_docs_final=num_docs_final,
temperature=temperature,
max_new_tokens=max_new_tokens,
top_p=top_p,
top_k=top_k,
penalty=penalty,
api_name="/chat"
)
# Return the assistant's reply
return response
# # OG code in V9
# def stream_chat_with_rag(
# message: str,
# history: list,
# client_name: str,
# system_prompt: str,
# num_retrieved_docs: int = 10,
# num_docs_final: int = 9,
# temperature: float = 0,
# max_new_tokens: int = 1024,
# top_p: float = 1.0,
# top_k: int = 20,
# penalty: float = 1.2,
# ):
# # Function to handle chat API call
# # def stream_chat_with_rag(message, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
# # response = client.predict(
# # message=message,
# # client_name="rosariarossi", # Hardcoded client name
# # system_prompt=system_prompt,
# # num_retrieved_docs=num_retrieved_docs,
# # num_docs_final=num_docs_final,
# # temperature=temperature,
# # max_new_tokens=max_new_tokens,
# # top_p=top_p,
# # top_k=top_k,
# # penalty=penalty,
# # api_name="/chat"
# # )
# # return response
# result = client.predict(
# message=message,
# client_name="rosariarossi",
# system_prompt="You are an expert assistant",
# num_retrieved_docs=10,
# num_docs_final=9,
# temperature=0,
# max_new_tokens=1024,
# top_p=1,
# top_k=20,
# penalty=1.2,
# api_name="/chat"
# )
# return result
# Function to handle PDF processing API call
def process_pdf(pdf_file):
return client.predict(
pdf_file=handle_file(pdf_file),
client_name="rosariarossi", # Hardcoded client name
api_name="/process_pdf2"
)[1] # Return only the result string
# Function to handle search API call
def search_api(query):
return client.predict(query=query, api_name="/search_with_confidence")
# Function to handle RAG API call
def rag_api(question):
return client.predict(question=question, api_name="/answer_with_rag")
# CSS for custom styling
CSS = """
# chat-container {
height: 100vh;
}
"""
# Title for the application
TITLE = "<h1 style='text-align:center;'>My Gradio Chat App</h1>"
# Create the Gradio Blocks interface
with gr.Blocks(css=CSS) as demo:
gr.HTML(TITLE)
## OG v9 comments
# gr.ChatInterface(
# fn=stream_chat_with_rag,
# chatbot=chatbot,
# fill_height=True,
# #gr.dropdown(['rosariarossi','bianchifiordaliso','lorenzoverdi'],label="Select Client"),
# additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
# additional_inputs=[
# gr.Dropdown(['rosariarossi','bianchifiordaliso','lorenzoverdi'],value="rosariarossi",label="Select Client", render=False,),
# gr.Textbox(
# # value="""Using the information contained in the context,
# # give a comprehensive answer to the question.
# # Respond only to the question asked, response should be concise and relevant to the question.
# # Provide the number of the source document when relevant.
# # If the answer cannot be deduced from the context, do not give an answer""",
# value ="""You are an expert assistant""",
# label="System Prompt",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=10,
# step=1,
# value=10,
# label="Number of Initial Documents to Retrieve",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=10,
# step=1,
# value=9,
# label="Number of Final Documents to Retrieve",
# render=False,
# ),
# gr.Slider(
# minimum=0.2,
# maximum=1,
# step=0.1,
# value=0,
# label="Temperature",
# render=False,
# ),
# gr.Slider(
# minimum=128,
# maximum=8192,
# step=1,
# value=1024,
# label="Max new tokens",
# render=False,
# ),
# gr.Slider(
# minimum=0.0,
# maximum=1.0,
# step=0.1,
# value=1.0,
# label="top_p",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=20,
# step=1,
# value=20,
# label="top_k",
# render=False,
# ),
# gr.Slider(
# minimum=0.0,
# maximum=2.0,
# step=0.1,
# value=1.2,
# label="Repetition penalty",
# render=False,
# ),
# ],
# )
with gr.Tab("Chat"):
chatbot = gr.Chatbot() # Create a chatbot interface
chat_interface = gr.ChatInterface(
fn=stream_chat_with_rag,
chatbot=chatbot,
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
additional_inputs=[
gr.Dropdown(['rosariarossi','bianchifiordaliso','lorenzoverdi'],value="rosariarossi",label="Select Client", render=False,),
gr.Textbox(
value="You are an expert assistant",
label="System Prompt",
render=False,
),
gr.Slider(
minimum=1,
maximum=10,
step=1,
value=10,
label="Number of Initial Documents to Retrieve",
render=False,
),
gr.Slider(
minimum=1,
maximum=10,
step=1,
value=9,
label="Number of Final Documents to Retrieve",
render=False,
),
gr.Slider(
minimum=0.2,
maximum=1,
step=0.1,
value=0,
label="Temperature",
render=False,
),
gr.Slider(
minimum=128,
maximum=8192,
step=1,
value=1024,
label="Max new tokens",
render=False,
),
gr.Slider(
minimum=0.0,
maximum=1.0,
step=0.1,
value=1.0,
label="Top P",
render=False,
),
gr.Slider(
minimum=1,
maximum=20,
step=1,
value=20,
label="Top K",
render=False,
),
gr.Slider(
minimum=0.0,
maximum=2.0,
step=0.1,
value=1.2,
label="Repetition Penalty",
render=False,
),
],
)
with gr.Tab("Process PDF"):
pdf_input = gr.File(label="Upload PDF File")
pdf_output = gr.Textbox(label="PDF Result", interactive=False)
pdf_button = gr.Button("Process PDF")
pdf_button.click(
process_pdf,
inputs=[pdf_input],
outputs=pdf_output
)
with gr.Tab("Search"):
query_input = gr.Textbox(label="Enter Search Query")
search_output = gr.Textbox(label="Search Confidence Result", interactive=False)
search_button = gr.Button("Search")
search_button.click(
search_api,
inputs=query_input,
outputs=search_output
)
with gr.Tab("Answer with RAG"):
question_input = gr.Textbox(label="Enter Question for RAG")
rag_output = gr.Textbox(label="RAG Answer Result", interactive=False)
rag_button = gr.Button("Get Answer")
rag_button.click(
rag_api,
inputs=question_input,
outputs=rag_output
)
# Launch the app
if __name__ == "__main__":
demo.launch()
# import gradio as gr
# from gradio_client import Client, handle_file
# import os
# # Define your Hugging Face token (make sure to set it as an environment variable)
# HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
# # Initialize the Gradio Client for the specified API
# client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
# # Function to handle chat API call
# def stream_chat_with_rag(message, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
# response = client.predict(
# message=message,
# client_name="rosariarossi", # Hardcoded client name
# system_prompt=system_prompt,
# num_retrieved_docs=num_retrieved_docs,
# num_docs_final=num_docs_final,
# temperature=temperature,
# max_new_tokens=max_new_tokens,
# top_p=top_p,
# top_k=top_k,
# penalty=penalty,
# api_name="/chat"
# )
# return response
# # Function to handle PDF processing API call
# def process_pdf(pdf_file):
# return client.predict(
# pdf_file=handle_file(pdf_file),
# client_name="rosariarossi", # Hardcoded client name
# api_name="/process_pdf2"
# )[1] # Return only the result string
# # Function to handle search API call
# def search_api(query):
# return client.predict(query=query, api_name="/search_with_confidence")
# # Function to handle RAG API call
# def rag_api(question):
# return client.predict(question=question, api_name="/answer_with_rag")
# # CSS for custom styling
# CSS = """
# # chat-container {
# height: 100vh;
# }
# """
# # Title for the application
# TITLE = "<h1 style='text-align:center;'>My Gradio Chat App</h1>"
# # Create the Gradio Blocks interface
# with gr.Blocks(css=CSS) as demo:
# gr.HTML(TITLE)
# with gr.Tab("Chat"):
# chatbot = gr.Chatbot() # Create a chatbot interface
# chat_interface = gr.ChatInterface(
# fn=stream_chat_with_rag,
# chatbot=chatbot,
# additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
# additional_inputs=[
# gr.Dropdown(
# ['rosariarossi', 'bianchifiordaliso', 'lorenzoverdi'],
# value="rosariarossi",
# label="Select Client",
# render=False,
# ),
# gr.Textbox(
# value="You are an expert assistant",
# label="System Prompt",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=10,
# step=1,
# value=10,
# label="Number of Initial Documents to Retrieve",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=10,
# step=1,
# value=9,
# label="Number of Final Documents to Retrieve",
# render=False,
# ),
# gr.Slider(
# minimum=0.2,
# maximum=1,
# step=0.1,
# value=0,
# label="Temperature",
# render=False,
# ),
# gr.Slider(
# minimum=128,
# maximum=8192,
# step=1,
# value=1024,
# label="Max new tokens",
# render=False,
# ),
# gr.Slider(
# minimum=0.0,
# maximum=1.0,
# step=0.1,
# value=1.0,
# label="Top P",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=20,
# step=1,
# value=20,
# label="Top K",
# render=False,
# ),
# gr.Slider(
# minimum=0.0,
# maximum=2.0,
# step=0.1,
# value=1.2,
# label="Repetition Penalty",
# render=False,
# ),
# ],
# )
# with gr.Tab("Process PDF"):
# pdf_input = gr.File(label="Upload PDF File")
# pdf_output = gr.Textbox(label="PDF Result", interactive=False)
# pdf_button = gr.Button("Process PDF")
# pdf_button.click(
# process_pdf,
# inputs=[pdf_input],
# outputs=pdf_output
# )
# with gr.Tab("Search"):
# query_input = gr.Textbox(label="Enter Search Query")
# search_output = gr.Textbox(label="Search Confidence Result", interactive=False)
# search_button = gr.Button("Search")
# search_button.click(
# search_api,
# inputs=query_input,
# outputs=search_output
# )
# with gr.Tab("Answer with RAG"):
# question_input = gr.Textbox(label="Enter Question for RAG")
# rag_output = gr.Textbox(label="RAG Answer Result", interactive=False)
# rag_button = gr.Button("Get Answer")
# rag_button.click(
# rag_api,
# inputs=question_input,
# outputs=rag_output
# )
# # Launch the app
# if __name__ == "__main__":
# demo.launch()
# import gradio as gr
# from gradio_client import Client, handle_file
# import os
# # Define your Hugging Face token (make sure to set it as an environment variable)
# HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
# # Initialize the Gradio Client for the specified API
# client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
# # Function to handle chat API call
# def stream_chat_with_rag(message, client_name, system_prompt, num_retrieved_docs, num_docs_final, temperature, max_new_tokens, top_p, top_k, penalty):
# response = client.predict(
# message=message,
# client_name=client_name,
# system_prompt=system_prompt,
# num_retrieved_docs=num_retrieved_docs,
# num_docs_final=num_docs_final,
# temperature=temperature,
# max_new_tokens=max_new_tokens,
# top_p=top_p,
# top_k=top_k,
# penalty=penalty,
# api_name="/chat"
# )
# return response
# # Function to handle PDF processing API call
# def process_pdf(pdf_file, client_name):
# return client.predict(
# pdf_file=handle_file(pdf_file),
# client_name=client_name,
# api_name="/process_pdf2"
# )[1] # Return only the result string
# # Function to handle search API call
# def search_api(query):
# return client.predict(query=query, api_name="/search_with_confidence")
# # Function to handle RAG API call
# def rag_api(question):
# return client.predict(question=question, api_name="/answer_with_rag")
# # Create the Gradio Blocks interface
# with gr.Blocks() as app:
# gr.Markdown("### Login")
# with gr.Row():
# username_input = gr.Textbox(label="Username", placeholder="Enter your username")
# password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
# with gr.Tab("Chat"):
# chatbot = gr.Chatbot() # Create a chatbot interface
# chat_interface = gr.ChatInterface(
# fn=stream_chat_with_rag,
# chatbot=chatbot,
# fill_height=True,
# additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
# additional_inputs=[
# gr.Dropdown(
# ['rosariarossi', 'bianchifiordaliso', 'lorenzoverdi'],
# value="rosariarossi",
# label="Select Client",
# render=False,
# ),
# gr.Textbox(
# value="You are an expert assistant",
# label="System Prompt",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=10,
# step=1,
# value=10,
# label="Number of Initial Documents to Retrieve",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=10,
# step=1,
# value=9,
# label="Number of Final Documents to Retrieve",
# render=False,
# ),
# gr.Slider(
# minimum=0.2,
# maximum=1,
# step=0.1,
# value=0,
# label="Temperature",
# render=False,
# ),
# gr.Slider(
# minimum=128,
# maximum=8192,
# step=1,
# value=1024,
# label="Max new tokens",
# render=False,
# ),
# gr.Slider(
# minimum=0.0,
# maximum=1.0,
# step=0.1,
# value=1.0,
# label="Top P",
# render=False,
# ),
# gr.Slider(
# minimum=1,
# maximum=20,
# step=1,
# value=20,
# label="Top K",
# render=False,
# ),
# gr.Slider(
# minimum=0.0,
# maximum=2.0,
# step=0.1,
# value=1.2,
# label="Repetition Penalty",
# render=False,
# ),
# ],
# )
# with gr.Tab("Process PDF"):
# pdf_input = gr.File(label="Upload PDF File")
# pdf_output = gr.Textbox(label="PDF Result", interactive=False)
# pdf_button = gr.Button("Process PDF")
# pdf_button.click(
# process_pdf,
# inputs=[pdf_input, client_name_dropdown],
# outputs=pdf_output
# )
# with gr.Tab("Search"):
# query_input = gr.Textbox(label="Enter Search Query")
# search_output = gr.Textbox(label="Search Confidence Result", interactive=False)
# search_button = gr.Button("Search")
# search_button.click(
# search_api,
# inputs=query_input,
# outputs=search_output
# )
# with gr.Tab("Answer with RAG"):
# question_input = gr.Textbox(label="Enter Question for RAG")
# rag_output = gr.Textbox(label="RAG Answer Result", interactive=False)
# rag_button = gr.Button("Get Answer")
# rag_button.click(
# rag_api,
# inputs=question_input,
# outputs=rag_output
# )
# # Launch the app
# app.launch()
# import gradio as gr
# from gradio_client import Client, handle_file
# import os
# # Define your Hugging Face token (make sure to set it as an environment variable)
# HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using env variable
# # Initialize the Gradio Client for the specified API
# client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
# # Authentication function
# def login(username, password):
# if username == "your_username" and password == "your_password": # Update with actual credentials
# return True
# else:
# return False
# # Function to handle different API calls based on user input
# def handle_api_call(username, password, message=None, client_name="rosariarossi",
# system_prompt="You are an expert assistant", num_retrieved_docs=10,
# num_docs_final=9, temperature=0, max_new_tokens=1024,
# top_p=1, top_k=20, penalty=1.2,
# pdf_file=None, query=None, question=None):
# if not login(username, password):
# return "Invalid credentials! Please try again."
# if message:
# # Handle chat message
# chat_result = client.predict(
# message=message,
# client_name=client_name,
# system_prompt=system_prompt,
# num_retrieved_docs=num_retrieved_docs,
# num_docs_final=num_docs_final,
# temperature=temperature,
# max_new_tokens=max_new_tokens,
# top_p=top_p,
# top_k=top_k,
# penalty=penalty,
# api_name="/chat"
# )
# return chat_result
# elif pdf_file:
# # Handle PDF file
# pdf_result = client.predict(
# pdf_file=handle_file(pdf_file),
# client_name=client_name,
# api_name="/process_pdf2"
# )
# return pdf_result[1] # Returning the string result from the PDF processing
# elif query:
# # Handle search query
# search_result = client.predict(query=query, api_name="/search_with_confidence")
# return search_result
# elif question:
# # Handle question for RAG
# rag_result = client.predict(question=question, api_name="/answer_with_rag")
# return rag_result
# else:
# return "No valid input provided!"
# # Create the Gradio Blocks interface
# with gr.Blocks() as app:
# gr.Markdown("### Login")
# with gr.Row():
# username_input = gr.Textbox(label="Username", placeholder="Enter your username")
# password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
# with gr.Tab("Chat"):
# message_input = gr.Textbox(label="Message", placeholder="Type your message here")
# gr.Markdown("### Client Options")
# client_name_dropdown = gr.Dropdown(
# label="Select Client",
# choices=["rosariarossi", "bianchifiordaliso", "lorenzoverdi"],
# value="rosariarossi"
# )
# system_prompt_input = gr.Textbox(
# label="System Prompt",
# placeholder="Enter system prompt here",
# value="You are an expert assistant"
# )
# num_retrieved_docs_slider = gr.Slider(
# label="Number of Initial Documents to Retrieve",
# minimum=1,
# maximum=100,
# step=1,
# value=10
# )
# num_docs_final_slider = gr.Slider(
# label="Number of Final Documents to Retrieve",
# minimum=1,
# maximum=100,
# step=1,
# value=9
# )
# temperature_slider = gr.Slider(
# label="Temperature",
# minimum=0,
# maximum=2,
# step=0.1,
# value=0
# )
# max_new_tokens_slider = gr.Slider(
# label="Max New Tokens",
# minimum=1,
# maximum=2048,
# step=1,
# value=1024
# )
# top_p_slider = gr.Slider(
# label="Top P",
# minimum=0,
# maximum=1,
# step=0.01,
# value=1
# )
# top_k_slider = gr.Slider(
# label="Top K",
# minimum=1,
# maximum=100,
# step=1,
# value=20
# )
# penalty_slider = gr.Slider(
# label="Repetition Penalty",
# minimum=1,
# maximum=5,
# step=0.1,
# value=1.2
# )
# chat_output = gr.Textbox(label="Chat Response", interactive=False)
# with gr.Tab("Process PDF"):
# pdf_input = gr.File(label="Upload PDF File")
# pdf_output = gr.Textbox(label="PDF Result", interactive=False)
# with gr.Tab("Search"):
# query_input = gr.Textbox(label="Enter Search Query")
# search_output = gr.Textbox(label="Search Confidence Result", interactive=False)
# with gr.Tab("Answer with RAG"):
# question_input = gr.Textbox(label="Enter Question for RAG")
# rag_output = gr.Textbox(label="RAG Answer Result", interactive=False)
# api_button = gr.Button("Submit")
# # Bind the button click to the handle_api_call function
# api_button.click(
# handle_api_call,
# inputs=[
# username_input, password_input,
# message_input, client_name_dropdown,
# system_prompt_input, num_retrieved_docs_slider,
# num_docs_final_slider, temperature_slider,
# max_new_tokens_slider, top_p_slider,
# top_k_slider, penalty_slider,
# pdf_input, query_input, question_input
# ],
# outputs=[
# chat_output, pdf_output, search_output, rag_output
# ]
# )
# # Launch the app
# app.launch()
# import gradio as gr
# from gradio_client import Client, handle_file
# import os
# # Define your Hugging Face token (make sure to set it as an environment variable)
# HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using env variable
# # Initialize the Gradio Client for the specified API
# client = Client("on1onmangoes/CNIHUB10724v9", hf_token=HF_TOKEN)
# # Authentication function
# def login(username, password):
# if username == "your_username" and password == "your_password": # Update with actual credentials
# return True
# else:
# return False
# # Function to handle different API calls based on user input
# def handle_api_call(username, password, audio_file=None, pdf_file=None, message=None, query=None, question=None):
# if not login(username, password):
# return "Invalid credentials! Please try again."
# if audio_file:
# # Handle audio file using the appropriate API
# result = client.predict(audio=handle_file(audio_file), api_name="/process_audio") # Example endpoint for audio processing
# return result
# elif pdf_file:
# # Handle PDF file
# pdf_result = client.predict(pdf_file=handle_file(pdf_file), client_name="rosariarossi", api_name="/process_pdf2")
# return pdf_result[1] # Returning the string result from the PDF processing
# elif message:
# # Handle chat message
# chat_result = client.predict(
# message=message,
# client_name="rosariarossi",
# system_prompt="You are an expert assistant",
# num_retrieved_docs=10,
# num_docs_final=9,
# temperature=0,
# max_new_tokens=1024,
# top_p=1,
# top_k=20,
# penalty=1.2,
# api_name="/chat"
# )
# return chat_result
# elif query:
# # Handle search query
# search_result = client.predict(query=query, api_name="/search_with_confidence")
# return search_result
# elif question:
# # Handle question for RAG
# rag_result = client.predict(question=question, api_name="/answer_with_rag")
# return rag_result
# else:
# return "No valid input provided!"
# # Create the Gradio Blocks interface
# with gr.Blocks() as app:
# gr.Markdown("### Login")
# with gr.Row():
# username_input = gr.Textbox(label="Username", placeholder="Enter your username")
# password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
# audio_input = gr.Audio(label="Upload Audio File", type="filepath")
# pdf_input = gr.File(label="Upload PDF File")
# message_input = gr.Textbox(label="Enter Message for Chat")
# query_input = gr.Textbox(label="Enter Search Query")
# question_input = gr.Textbox(label="Enter Question for RAG")
# output_text = gr.Textbox(label="Output", interactive=False)
# # Bind the button click to the handle_api_call function
# api_button = gr.Button("Submit")
# api_button.click(
# handle_api_call,
# inputs=[username_input, password_input, audio_input, pdf_input, message_input, query_input, question_input],
# outputs=output_text
# )
# # Launch the app
# app.launch()
# import gradio as gr
# # Define a function for the main application
# def greet(name):
# return f"Hello {name}!"
# # Define a function for the authentication
# def login(username, password):
# if username == "your_username" and password == "your_password":
# return True
# else:
# return False
# # Create the Gradio Blocks interface
# with gr.Blocks() as app:
# gr.Markdown("### Login")
# with gr.Row():
# username_input = gr.Textbox(label="Username", placeholder="Enter your username")
# password_input = gr.Textbox(label="Password", placeholder="Enter your password", type="password")
# login_button = gr.Button("Login")
# output_text = gr.Textbox(label="Output", interactive=False)
# # Function to handle login and display greeting
# def handle_login(username, password):
# if login(username, password):
# # Clear the password field and display the greeting
# #password_input.clear()
# return greet(username)
# else:
# return "Invalid credentials! Please try again."
# # Bind the button click to the handle_login function
# login_button.click(handle_login, inputs=[username_input, password_input], outputs=output_text)
# # Launch the app
# app.launch()
|