import gradio as gr import torch from transformers import pipeline # Initialize the local pipeline for the model pipe = pipeline("text-generation", model="microsoft/Phi-3-mini-4k-instruct", torch_dtype=torch.bfloat16, device_map="auto") def respond( message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p, ): messages = [{"role": "system", "content": system_message}] for val in history: if val[0]: messages.append({"role": "user", "content": val[0]}) if val[1]: messages.append({"role": "assistant", "content": val[1]}) messages.append({"role": "user", "content": message}) response = "" # Use local pipeline to gen text for message in pipe( messages, max_new_tokens=max_tokens, temperature=temperature, do_sample=True, top_p=top_p, ): token = message['generated_text'][-1]['content'] response += token yield response # Custom CSS for header and logo custom_css = """ #header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; } #logo { height: 50px; /* Set the height of the logo */ width: auto; /* Maintain aspect ratio */ position: absolute; /* Position the logo */ top: 20px; /* Distance from the top */ right: 20px; /* Distance from the right */ } """ # Gradio interface demo = gr.ChatInterface( respond, title="
