Spaces:
Sleeping
Sleeping
import gradio as gr | |
from huggingface_hub import InferenceClient | |
from sae_auto_interp.sae import Sae | |
""" | |
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 | |
CITATION_BUTTON_TEXT = """ | |
@misc{zhang2024largemultimodalmodelsinterpret, | |
title={Large Multi-modal Models Can Interpret Features in Large Multi-modal Models}, | |
author={Kaichen Zhang and Yifei Shen and Bo Li and Ziwei Liu}, | |
year={2024}, | |
eprint={2411.14982}, | |
archivePrefix={arXiv}, | |
primaryClass={cs.CV}, | |
url={https://arxiv.org/abs/2411.14982}, | |
} | |
""" | |
with gr.Blocks() as demo: | |
gr.Markdown( | |
""" | |
# Large Multi-modal Models Can Interpret Features in Large Multi-modal Models | |
π [ArXiv Paper](https://arxiv.org/abs/2411.14982) | π [LMMs-Lab Homepage](https://lmms-lab.framer.ai) | π€ [Huggingface Collections](https://huggingface.co./collections/lmms-lab/llava-sae-674026e4e7bc8c29c70bc3a3) | |
""" | |
) | |
with gr.Tabs(elem_classes="tab-buttons") as tabs: | |
with gr.TabItem("Visualization of Activations", elem_id="visualization", id=0): | |
image = gr.Image() | |
with gr.TabItem("Steering Model", elem_id="steering", id=2): | |
chatbot = gr.Chatbot() | |
with gr.Row(): | |
with gr.Accordion("π Citation", open=False): | |
gr.Markdown("```bib\n" + CITATION_BUTTON_TEXT + "\n```") | |
if __name__ == "__main__": | |
demo.launch() | |