File size: 1,097 Bytes
f38d151 ea7f2d5 0202b9f f38d151 ed5f46c f38d151 ed5f46c ea7f2d5 ed5f46c 0202b9f ed5f46c 51442f4 ed5f46c 77c6433 ed5f46c 51442f4 ed5f46c 77c6433 ed5f46c 4684045 a45a39f 4684045 77c6433 ed5f46c 4684045 0202b9f ed5f46c ff74a22 0202b9f ed5f46c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
import os
from huggingface_hub import InferenceClient
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
def respond(message, history: list[tuple[str, str]]):
system_rules = os.getenv("SYSTEM_RULES")
max_tokens = 512
temperature = 0.75
top_p = 0.95
messages = [{"role": "system", "content": system_rules}]
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 = ""
for message in client.chat_completion(
messages,
max_tokens=4096,
stream=True,
temperature=temperature,
top_p=top_p,
):
token = message.choices[0].delta.content
response += token
yield response
demo = gr.ChatInterface(respond, description="This chatbot doesn't have restrictions. Use responsibly.", theme="Yntec/HaleyCH_Theme_Orange")
if __name__ == "__main__":
demo.launch() |