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 interactive app leverages the power of a fine-tuned Phi 2 AI model to provide insightful responses. Type your query below and witness AI in action.

''') 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-780') tokenizer = AutoTokenizer.from_pretrained('checkpoint-780', trust_remote_code=True) tokenizer.pad_token = tokenizer.eos_token