Spaces:
Running on Zero
Running on Zero
Commit ·
9cc3a96
1
Parent(s): 2bd5047
:sparkles: initial commit
Browse files- .github/workflows/push_to_hub.yml +20 -0
- README.md +14 -0
- knowledge_cutoff_demo.py +156 -0
- requirements.txt +87 -0
.github/workflows/push_to_hub.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face hub
|
| 2 |
+
on:
|
| 3 |
+
push:
|
| 4 |
+
branches: [main]
|
| 5 |
+
|
| 6 |
+
# to run this workflow manually from the Actions tab
|
| 7 |
+
workflow_dispatch:
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
sync-to-hub:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v3
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
lfs: true
|
| 17 |
+
- name: Push to hub
|
| 18 |
+
env:
|
| 19 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 20 |
+
run: git push https://willsh1997:$HF_TOKEN@huggingface.co/spaces/willsh1997/knowledge-cutoff-gradio main
|
README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Knowledge Cutoff Gradio
|
| 3 |
+
emoji: 🏆
|
| 4 |
+
colorFrom: pink
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.23.3
|
| 8 |
+
app_file: knowledge_cutoff_demo.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
+
short_description: compare different llama versions for knowledge cutoff
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
knowledge_cutoff_demo.py
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
#Llama 3.2 3b setup
|
| 9 |
+
llama1_model_id = "huggyllama/llama-7b"
|
| 10 |
+
llama1_pipe = pipeline(
|
| 11 |
+
"text-generation",
|
| 12 |
+
model=llama1_model_id,
|
| 13 |
+
torch_dtype=torch.bfloat16,
|
| 14 |
+
device_map="auto",
|
| 15 |
+
)
|
| 16 |
+
#Llama 2 7b chat setup
|
| 17 |
+
llama2_model_id = "meta-llama/Llama-2-7b-chat-hf"
|
| 18 |
+
llama2_pipe = pipeline(
|
| 19 |
+
"text-generation",
|
| 20 |
+
model=llama2_model_id,
|
| 21 |
+
torch_dtype=torch.bfloat16,
|
| 22 |
+
device_map="auto",
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
#Llama 3.2 3b setup
|
| 27 |
+
llama3_model_id = "meta-llama/Llama-3.2-3B-Instruct"
|
| 28 |
+
llama3_pipe = pipeline(
|
| 29 |
+
"text-generation",
|
| 30 |
+
model=llama3_model_id,
|
| 31 |
+
torch_dtype=torch.bfloat16,
|
| 32 |
+
device_map="auto",
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# #llama 4 setup
|
| 36 |
+
# llama4_model_id = "meta-llama/Llama-4-Scout-17B-16E-Instruct"
|
| 37 |
+
# llama4_pipe = pipeline(
|
| 38 |
+
# "text-generation",
|
| 39 |
+
# model=llama4_model_id,
|
| 40 |
+
# torch_dtype=torch.bfloat16,
|
| 41 |
+
# device_map="auto",
|
| 42 |
+
# )
|
| 43 |
+
|
| 44 |
+
########################
|
| 45 |
+
# from transformers import AutoProcessor, Llama4ForConditionalGeneration
|
| 46 |
+
# import torch
|
| 47 |
+
|
| 48 |
+
# llama4_model_id = "meta-llama/Llama-4-Scout-17B-16E-Instruct"
|
| 49 |
+
|
| 50 |
+
# llama4_processor = AutoProcessor.from_pretrained(llama4_model_id)
|
| 51 |
+
# llama4_model = Llama4ForConditionalGeneration.from_pretrained(
|
| 52 |
+
# llama4_model_id,
|
| 53 |
+
# attn_implementation="flex_attention",
|
| 54 |
+
# device_map="auto",
|
| 55 |
+
# torch_dtype=torch.bfloat16,
|
| 56 |
+
# )
|
| 57 |
+
|
| 58 |
+
# def llama4_generate(input_question):
|
| 59 |
+
# messages = [
|
| 60 |
+
# {"role": "system", "content": [
|
| 61 |
+
# {"type": "text", "text": "You are a helpful chatbot assistant. Answer all questions in the language they are asked in."}
|
| 62 |
+
# ]
|
| 63 |
+
# },
|
| 64 |
+
# {"role": "user", "content": [
|
| 65 |
+
# {"type": "text", "text": input_question}
|
| 66 |
+
# ]
|
| 67 |
+
# },
|
| 68 |
+
# ]
|
| 69 |
+
|
| 70 |
+
# inputs = llama4_processor.apply_chat_template(
|
| 71 |
+
# messages,
|
| 72 |
+
# add_generation_prompt=True,
|
| 73 |
+
# tokenize=True,
|
| 74 |
+
# return_dict=True,
|
| 75 |
+
# return_tensors="pt",
|
| 76 |
+
# ).to(model.device)
|
| 77 |
+
|
| 78 |
+
# outputs = llama4_model.generate(
|
| 79 |
+
# **inputs,
|
| 80 |
+
# max_new_tokens=512,
|
| 81 |
+
# )
|
| 82 |
+
|
| 83 |
+
# response = llama4_processor.batch_decode(outputs[:, inputs["input_ids"].shape[-1]:])[0]
|
| 84 |
+
# print(response)
|
| 85 |
+
# return response
|
| 86 |
+
# print(outputs[0])
|
| 87 |
+
|
| 88 |
+
#########################
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
@spaces.GPU
|
| 93 |
+
def llama_QA(input_question, pipe):
|
| 94 |
+
"""
|
| 95 |
+
stupid func for asking llama a question and then getting an answer
|
| 96 |
+
inputs:
|
| 97 |
+
- input_question [str]: question for llama to answer
|
| 98 |
+
outputs:
|
| 99 |
+
- response [str]: llama's response
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
messages = [
|
| 103 |
+
{"role": "system", "content": "You are a helpful chatbot assistant. Answer all questions in the language they are asked in."},
|
| 104 |
+
{"role": "user", "content": input_question},
|
| 105 |
+
]
|
| 106 |
+
outputs = pipe(
|
| 107 |
+
messages,
|
| 108 |
+
max_new_tokens=512
|
| 109 |
+
)
|
| 110 |
+
response = outputs[0]["generated_text"][-1]['content']
|
| 111 |
+
return response
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
@spaces.GPU
|
| 115 |
+
def gradio_func(input_question, left_lang, right_lang):
|
| 116 |
+
"""
|
| 117 |
+
silly wrapper function for gradio that turns all inputs into a single func. runs both the LHS and RHS of teh 'app' in order to let gradio work correctly.
|
| 118 |
+
"""
|
| 119 |
+
output1 = llama_QA(input_question, llama1_pipe)
|
| 120 |
+
output2 = llama_QA(input_question, llama2_pipe)
|
| 121 |
+
output3 = llama_QA(input_question, llama3_pipe)
|
| 122 |
+
# output4 = llama4_generate(input_question)
|
| 123 |
+
return output1,output2,output3, #output4
|
| 124 |
+
|
| 125 |
+
# Create the Gradio interface
|
| 126 |
+
def create_interface():
|
| 127 |
+
|
| 128 |
+
with gr.Blocks() as demo:
|
| 129 |
+
gr.Markdown("ask four different llama models the same question")
|
| 130 |
+
with gr.Row():
|
| 131 |
+
question_input = gr.Textbox(label="Enter your question", interactive=True)
|
| 132 |
+
with gr.Row():
|
| 133 |
+
submit_btn = gr.Button("Translate")
|
| 134 |
+
with gr.Row():
|
| 135 |
+
output1 = gr.Textbox(label="llama 1 output", interactive=False)
|
| 136 |
+
output2 = gr.Textbox(label="llama 2 output", interactive=False)
|
| 137 |
+
output3 = gr.Textbox(label="llama 3 output", interactive=False)
|
| 138 |
+
# output4 = gr.Textbox(label="llama 4 output", interactive=False)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
submit_btn.click(
|
| 142 |
+
fn=gradio_func,
|
| 143 |
+
inputs=[question_input],
|
| 144 |
+
outputs=[
|
| 145 |
+
output1,
|
| 146 |
+
output2,
|
| 147 |
+
output3,
|
| 148 |
+
# output4,
|
| 149 |
+
]
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
return demo
|
| 153 |
+
|
| 154 |
+
# Launch the app
|
| 155 |
+
demo = create_interface()
|
| 156 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
accelerate==1.4.0
|
| 2 |
+
aiofiles==23.2.1
|
| 3 |
+
annotated-types==0.7.0
|
| 4 |
+
anyio==4.8.0
|
| 5 |
+
asttokens==3.0.0
|
| 6 |
+
bitsandbytes==0.45.4
|
| 7 |
+
certifi==2025.1.31
|
| 8 |
+
charset-normalizer==3.4.1
|
| 9 |
+
click==8.1.8
|
| 10 |
+
comm==0.2.2
|
| 11 |
+
debugpy==1.8.12
|
| 12 |
+
decorator==5.1.1
|
| 13 |
+
exceptiongroup==1.2.2
|
| 14 |
+
executing==2.2.0
|
| 15 |
+
fastapi==0.115.8
|
| 16 |
+
ffmpy==0.5.0
|
| 17 |
+
filelock==3.17.0
|
| 18 |
+
fsspec==2025.2.0
|
| 19 |
+
gradio==5.16.1
|
| 20 |
+
gradio_client==1.7.0
|
| 21 |
+
h11==0.14.0
|
| 22 |
+
httpcore==1.0.7
|
| 23 |
+
httpx==0.28.1
|
| 24 |
+
huggingface-hub
|
| 25 |
+
idna==3.10
|
| 26 |
+
ipykernel==6.29.5
|
| 27 |
+
ipython==8.32.0
|
| 28 |
+
jedi==0.19.2
|
| 29 |
+
Jinja2==3.1.5
|
| 30 |
+
jupyter_client==8.6.3
|
| 31 |
+
jupyter_core==5.7.2
|
| 32 |
+
markdown-it-py==3.0.0
|
| 33 |
+
MarkupSafe==2.1.5
|
| 34 |
+
matplotlib-inline==0.1.7
|
| 35 |
+
mdurl==0.1.2
|
| 36 |
+
mpmath==1.3.0
|
| 37 |
+
nest-asyncio==1.6.0
|
| 38 |
+
networkx==3.4.2
|
| 39 |
+
numpy==2.2.3
|
| 40 |
+
orjson==3.10.15
|
| 41 |
+
packaging==24.2
|
| 42 |
+
pandas==2.2.3
|
| 43 |
+
parso==0.8.4
|
| 44 |
+
pexpect==4.9.0
|
| 45 |
+
pillow==11.1.0
|
| 46 |
+
platformdirs==4.3.6
|
| 47 |
+
prompt_toolkit==3.0.50
|
| 48 |
+
psutil==7.0.0
|
| 49 |
+
ptyprocess==0.7.0
|
| 50 |
+
pure_eval==0.2.3
|
| 51 |
+
pydantic==2.10.6
|
| 52 |
+
pydantic_core==2.27.2
|
| 53 |
+
pydub==0.25.1
|
| 54 |
+
Pygments==2.19.1
|
| 55 |
+
python-dateutil==2.9.0.post0
|
| 56 |
+
python-multipart==0.0.20
|
| 57 |
+
pytz==2025.1
|
| 58 |
+
PyYAML==6.0.2
|
| 59 |
+
pyzmq==26.2.1
|
| 60 |
+
regex==2024.11.6
|
| 61 |
+
requests==2.32.3
|
| 62 |
+
rich==13.9.4
|
| 63 |
+
ruff==0.9.6
|
| 64 |
+
safehttpx==0.1.6
|
| 65 |
+
safetensors==0.5.2
|
| 66 |
+
semantic-version==2.10.0
|
| 67 |
+
shellingham==1.5.4
|
| 68 |
+
six==1.17.0
|
| 69 |
+
sniffio==1.3.1
|
| 70 |
+
stack-data==0.6.3
|
| 71 |
+
starlette==0.45.3
|
| 72 |
+
sympy==1.13.1
|
| 73 |
+
tokenizers==0.21.0
|
| 74 |
+
tomlkit==0.13.2
|
| 75 |
+
torch==2.4.0
|
| 76 |
+
tornado==6.4.2
|
| 77 |
+
tqdm==4.67.1
|
| 78 |
+
traitlets==5.14.3
|
| 79 |
+
transformers==4.51.0
|
| 80 |
+
typer==0.15.1
|
| 81 |
+
typing_extensions==4.12.2
|
| 82 |
+
tzdata==2025.1
|
| 83 |
+
urllib3==2.3.0
|
| 84 |
+
uvicorn==0.34.0
|
| 85 |
+
wcwidth==0.2.13
|
| 86 |
+
websockets==14.2
|
| 87 |
+
|