MUSK-1 / app.py
Elieon's picture
Update app.py
df8b191 verified
raw
history blame
1.82 kB
import gradio as gr
from huggingface_hub import InferenceClient
client = InferenceClient(model="HuggingFaceH4/zephyr-7b-beta")
system_message = ("This is MUSK-1, developed by a 14 year old AI engineer Arjun Singh at Elieon.")
# Function to generate responses using the LLM
def respond(
message,
history: list[tuple[str, str]],
max_tokens,
temperature,
top_p,
):
# Construct the message history for the API request
messages = [{"role": "system", "content": system_message}]
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})
messages.append({"role": "user", "content": message})
response = ""
# Stream the response tokens from the model
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
# Create a Gradio ChatInterface with custom styling
custom_css = """
.css-1rw10a3 {
height: 500px; /* Adjust height as needed */
overflow-y: scroll; /* Add scrollbar if content exceeds height */
}
"""
demo = gr.ChatInterface(
respond,
additional_inputs=[
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
],
css=custom_css, # Apply custom CSS styling
)
# Launch the Gradio app
if __name__ == "__main__":
demo.launch()