import torch from transformers import AutoModelForCausalLM, AutoTokenizer def extract_responses(text): """ Extracts and returns the responses from the text, excluding the parts between and including the [INST] tags. Args: text (str): The input text containing responses and [INST] tags. Returns: str: The extracted responses. """ import re # Split the text by [INST] tags and accumulate non-tag parts parts = re.split(r'\[INST\].*?\[/INST\]', text, flags=re.DOTALL) cleaned_text = "".join(parts) # Return the cleaned and trimmed text return cleaned_text.strip() def generate_html(): return( ''' Your Gradio App

AI Assistant

This chatbot is an interactive application which leverages the power of a fine-tuned Phi 2 AI model to provide responses for the given queries. Type your query below and start chatting.

''') def generate_footer(): return( ''' Your Gradio App ''') model = AutoModelForCausalLM.from_pretrained( "microsoft/phi-2", torch_dtype=torch.float32, device_map="cpu", trust_remote_code=True ) model.load_adapter('checkpoint-1100') tokenizer = AutoTokenizer.from_pretrained('checkpoint-1100', trust_remote_code=True) tokenizer.pad_token = tokenizer.eos_token