Test-subject / app.py
Onyxl's picture
TeraMite Factory Co. β€” deploy πŸš€
b0cc55d verified
Raw
History Blame Contribute Delete
1.28 kB
import gradio as gr
from huggingface_hub import InferenceClient
AGENT_NAME = "Test-subject"
MODEL_ID = "mistralai/Mistral-7B-Instruct-v0.3"
SYSTEM_PROMPT = "You are Test-subject, a helpful AI assistant powered by mistralai/Mistral-7B-Instruct-v0.3. Be friendly, concise, and helpful."
BRIDGE = ['πŸ€— Hugging Face']
client = InferenceClient(model=MODEL_ID)
def chat(message, history):
msgs = [{"role": "system", "content": SYSTEM_PROMPT}]
for h in history:
msgs.append({"role": "user", "content": h[0]})
msgs.append({"role": "assistant", "content": h[1]})
msgs.append({"role": "user", "content": message})
response = ""
for chunk in client.chat_completion(messages=msgs, max_tokens=1024, stream=True):
delta = chunk.choices[0].delta.content
if delta:
response += delta
yield response
bridge_note = ("\n\nπŸŒ‰ **Bridge Connect:** " + " Β· ".join(BRIDGE)) if BRIDGE else ""
demo = gr.ChatInterface(
fn=chat,
title=f"πŸ’¬ {AGENT_NAME}",
description=f"Your personal AI agent powered by `{MODEL_ID}`.{bridge_note}",
examples=["Hello! What can you do?", "Tell me something interesting.", "Help me brainstorm ideas."],
)
if __name__ == "__main__":
demo.launch()