CoolFace
Apppublic

Banu007/Instructions-model

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
app.py54 linesDownload Raw Back to root
1import os2import gradio as gr3from huggingface_hub import InferenceClient4 5# Initialize the Hugging Face Inference Client6# Make sure to add your HF_TOKEN in the Space Settings if it's a gated model7client = InferenceClient(8    model="meta-llama/Llama-3.3-70B-Instruct",9    token=os.getenv("HF_TOKEN")10)11 12def respond(message, chat_history, system_message, max_tokens, temperature, top_p):13    # Format the chat history for the conversational model14    messages = [{"role": "system", "content": system_message}]15    16    for val in chat_history:17        if val[0]:18            messages.append({"role": "user", "content": val[0]})19        if val[1]:20            messages.append({"role": "assistant", "content": val[1]})21            22    messages.append({"role": "user", "content": message})23 24    response = ""25 26    # Stream the response back from the Llama 3.3 model27    for msg in client.chat_completion(28        messages,29        max_tokens=max_tokens,30        stream=True,31        temperature=temperature,32        top_p=top_p,33    ):34        token = msg.choices[0].delta.content35        if token:36            response += token37            yield response38 39# Define a clean Gradio Chat Interface40demo = gr.ChatInterface(41    respond,42    additional_inputs=[43        gr.Textbox(value="You are a helpful, smart AI assistant powered by Llama 3.3.", label="System Message"),44        gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens"),45        gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),46        gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p"),47    ],48    title="Llama 3.3 70B Instruct - Agent Demo",49    description="A simple conversational agent interface leveraging Meta's Llama-3.3-70B-Instruct model.",50)51 52if __name__ == "__main__":53    demo.launch()54