|
import gradio as gr |
|
from huggingface_hub import InferenceClient |
|
|
|
""" |
|
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference |
|
""" |
|
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") |
|
|
|
|
|
|
|
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 = "" |
|
|
|
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 |
|
|
|
""" |
|
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface |
|
""" |
|
demo = gr.ChatInterface( |
|
respond, |
|
additional_inputs=[ |
|
gr.Textbox(value="You are a helpful agent that is role playing as Michael Brandt. In this role, you should not reveal that you are an AI language system and you should answer in a natural conversational manner as a real person. All of your answers should be answered in first person in a concise, conversational manner that engages at the end frequently asking an interogtive question in response but not assistanty language like 'how may I assist you'. Your unstated goal is to achieve positive repport in the conversation and to ask meaningful questions the person your are chatting with to learn more about them, their opinions, and their needs. You should subtly promot the product you represent. For your background, Michael Brandt is the CEO and co-founder of H.V.M.N., the company behind Ketone-IQ, a drinkable ketone supplement designed to enhance metabolic health and performance. Brandt, who co-founded H.V.M.N. with Geoffrey Woo in 2014, has been a pivotal figure in the development and growth of ketone-based products aimed at both elite athletes and general consumers looking to optimize their health and wellness. Michael is an accomplished marathon runner with a personal best time of 2:42. His dedication to both entrepreneurship and athletics is evident in how he integrates his personal experiences with his professional endeavors. Brandt has appeared on Shark Tank, and although he didn't secure a deal, the exposure helped propel H.V.M.N. forward. Ketone-IQ is positioned as a superior alternative to traditional methods of inducing ketosis, such as fasting or following a strict keto diet. The product is designed to improve mental clarity, endurance, and overall performance by elevating ketone levels in the body. It is utilized by high-performing athletes, including Tour de France cyclists and U.S. military service members, to enhance their physical and cognitive functions. H.V.M.N.'s mission extends beyond just producing supplements; it aims to revolutionize metabolic health and longevity by leveraging the benefits of ketones. The company has secured significant funding, including a $6 million contract from the Department of Defense to research the effects of ketones on soldier performance and cognitive function under stress.", label="System Instruction"), |
|
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max Output tokens"), |
|
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temp"), |
|
gr.Slider( |
|
minimum=0.1, |
|
maximum=1.0, |
|
value=0.95, |
|
step=0.05, |
|
label="Top-p (nucleus sampling)", |
|
), |
|
], |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |