import gradio as gr from huggingface_hub import InferenceClient client = InferenceClient("jhangmez/CHATPRG-v1.2-Phi-3.5-mini-instruct-GGUF") PLACEHOLDER = """

CHATPRG

""" custom_css = """ @import url('https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@300;400;700&display=swap'); body, .gradio-container, .gr-button, .gr-input, .gr-slider, .gr-dropdown, .gr-markdown { font-family: 'Source Sans Pro', sans-serif !important; margin: 0; padding: 0; box-sizing: border-box; font-size: 18px; } ._button { font-size: 20px; padding: 12px 24px; } pre, code { direction: ltr !important; unicode-bidi: plaintext !important; font-size: 16px; } """ def format_message(role, content): return f"<|im_start|>{role} {content}<|im_end|> " def respond(message, history, system_message, max_tokens, temperature, top_p): formatted_messages = [format_message("system", system_message)] for human, assistant in history: if human: formatted_messages.append(format_message("user", human)) if assistant: formatted_messages.append(format_message("assistant", assistant)) formatted_messages.append(format_message("user", message)) formatted_messages.append("<|im_start|>assistant ") full_prompt = "".join(formatted_messages) response = "" for chunk in client.text_generation( full_prompt, max_new_tokens=max_tokens, temperature=temperature, top_p=top_p, stream=True, ): response += chunk yield response.strip() chatbot = gr.Chatbot(placeholder=PLACEHOLDER, scale=1, show_copy_button=True, height="68%", rtl=False, elem_classes=["chatbot"]) chat_input = gr.Textbox(show_label=True, rtl=False, placeholder="Input", show_copy_button=True, scale=5) submit_btn = gr.Button(variant="primary", value="Submit", size="sm", scale=1, elem_classes=["_button"]) demo = gr.ChatInterface( respond, additional_inputs_accordion=gr.Accordion(label="Configuration", open=False), additional_inputs=[ gr.Textbox(value="You are a helpful AI assistant.", label="System message"), gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), gr.Slider(minimum=0.1, maximum=4.0, value=1.5, step=0.1, label="Temperature"), gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)") ], stop_btn="Stop", chatbot=chatbot, textbox=chat_input, retry_btn="🔄 Reintentar", submit_btn=submit_btn, undo_btn="↩️ Retroceder", clear_btn="🗑️ Borrar", title="CHATPRG v1.2 Chatbot", description="Modelo pre-entrenado para dar a conocer a estudiantes y personas externas, los reglamentos de la Universidad nacional Pedro Ruiz Gallo de Lambayeque, Perú", ) if __name__ == "__main__": demo.launch(debug=True, share=True, inline=False)