# # Mount Google Drive # from google.colab import drive # drive.mount('/content/drive') import gradio as gr from transformers import AutoModel, TFAutoModel # Modèle Hugging Face à partir de l'identifiant du modèle model_name = "gpt2" huggingface_model = AutoModel.from_pretrained(model_name) # Spécifiez l'identifiant de référentiel correct sans informations supplémentaires repo_name = "motofanacc/monModel" # Chemin vers les poids de votre modèle dans votre référentiel model_checkpoint = "main" # Charger le modèle à partir de Hugging Face Hub model = TFAutoModel.from_pretrained(repo_name, from_pt=True, model_checkpoint=model_checkpoint) #a # # Charger les poids TensorFlow # tensorflow_weights_path = "motofanacc/GradioChatBot/tree/main/Checkpoints" # tensorflow_model = TFAutoModel.from_pretrained(tensorflow_weights_path) def generate_text(model, input_text, max_length=50): return model.generate(input_text, max_length=max_length) # preprocessor = keras_nlp.models.GPT2CausalLMPreprocessor.from_preset( # "gpt2_base_en", # sequence_length=128, # ) # gpt2_lm = keras_nlp.models.GPT2CausalLM.from_preset( # "gpt2_base_en", # preprocessor=preprocessor, # ) # gpt2_lm.load_weights('/content/drive/MyDrive/Checkpoints/weights') # Gradio app # Icon by Freepik # Icon by Freepik theme = gr.themes.Soft().set( background_fill_primary='white', background_fill_primary_dark='white', ) with gr.Blocks(theme=theme,css=""" .gradio-container { background-color: white; width: 70vw; } #chatbot{ background-image: url("https://png.pngtree.com/thumb_back/fh260/background/20201014/pngtree-breast-cancer-awareness-pink-ribbons-background-design-image_417234.jpg"); } #chatbot .bubble-wrap::-webkit-scrollbar { width: 20px; } #chatbot .bubble-wrap::-webkit-scrollbar-thumb { background-color: whitesmoke; border-radius: 20px; border: 6px solid transparent; background-clip: content-box; } #chatbot .bubble-wrap::-webkit-scrollbar-thumb:hover { background-color: grey; } #chatbot .bubble-wrap::-webkit-scrollbar-track { background-color: transparent; } #chatbot .message p{ text-align: start; color: white; } h1, p { text-align: center; color: black; } body #footer_note { text-align: center; font-size: x-small; font-weight:bold; } .label { display:none; } textarea, .gallery-item, .gallery-item:hover { color: black; border: 1px black solid; background-color: white; } .user { background-color: #374151; } .user { background-color: #111827; } .gallery-item:hover { color: white; border: 1px black solid; background-color: black; } body gradio-app { background-color: white; } """) as demo: gr.HTML(f"""
Here you can ask all questions about cancer
""") def return_message(message, history, model=huggingface_model, max_length=128): if len(message) <= 1: gr.Warning('Please enter a message with more than one character.') elif len(message) > max_length: gr.Warning(f"Input should not exceed {max_length} characters.") else: cancer_answer = generate_text(model, message) message = "**You**\n" + message history.append([message, f"**CancerBot**\n{cancer_answer}"]) return "", history chatbot = gr.Chatbot( height="60vh", bubble_full_width=True, avatar_images=(["/content/drive/MyDrive/Data/avatar.png", "/content/drive/MyDrive/Data/robot.png"]), show_copy_button=True, likeable=True, layout='bubble', elem_id='chatbot', show_label=False, ) with gr.Row(): input_box = gr.Textbox(placeholder="Message CancerBot...", container=False, scale=9) submit_btn = gr.Button(value="⬆", scale=1) submit_btn.click(return_message, [input_box, chatbot],[input_box, chatbot]) examples = gr.Examples(examples=["What is a thyroid cancer ?", "How can I know that I have a lung cancer ?", "How many types of cancer ?"], inputs=[input_box], label="") input_box.submit(return_message, [input_box, chatbot],[input_box, chatbot]) gr.HTML(f""" """) demo.queue(default_concurrency_limit=34) # 32 students, 2 teachers demo.launch(share=True)