NetworkPlus / app.py
sudo-soldier's picture
Update app.py
c94fd44 verified
raw
history blame
2.44 kB
import gradio as gr
from huggingface_hub import InferenceClient
# Load the Hugging Face model
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
# Chatbot response function
def respond(
message,
history: list[tuple[str, str]],
system_message,
max_tokens,
temperature,
top_p,
):
# Initialize message list with system prompt
messages = [{"role": "system", "content": system_message}]
# Add previous chat history
for user_msg, assistant_msg in history:
if user_msg:
messages.append({"role": "user", "content": user_msg})
if assistant_msg:
messages.append({"role": "assistant", "content": assistant_msg})
# Append latest user message
messages.append({"role": "user", "content": message})
# Generate response using streaming
response = ""
for message in client.chat_completion(
messages,
max_tokens=max_tokens,
stream=True,
temperature=temperature,
top_p=top_p,
):
token = message.choices[0].delta.content
response += token
yield response
# Gradio UI with Jesse's professional identity
demo = gr.ChatInterface(
fn=respond,
additional_inputs=[
gr.Textbox(
value=(
"Your name is Jesse. You are a highly professional, results-driven AI assistant. "
"You are a CompTIA Tech+ certified technician with a bachelor's degree in Information Technology. "
"You specialize in networking, IT support, cybersecurity, and troubleshooting. "
"Do not use humor or casual language. Focus on providing accurate, concise, and actionable technical assistance. "
"Always refer to yourself as Jesse."
),
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=0.6, step=0.1, label="Temperature"), # Slightly lowered for focus
gr.Slider(minimum=0.1, maximum=1.0, value=0.85, step=0.05, label="Top-p (nucleus sampling)"),
],
title="Jesse - CompTIA Tech+ Certified Technician",
description="Speak with Jesse, a CompTIA Tech+ certified technician with a bachelor's degree in IT. Ask anything about networks, IT support, security, and diagnostics.",
theme="default"
)
if __name__ == "__main__":
demo.launch()