Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
model_name = "rubenroy/Zurich-7b-GCv2-5m"
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 8 |
+
model_name,
|
| 9 |
+
torch_dtype=torch.bfloat16,
|
| 10 |
+
device_map="auto"
|
| 11 |
+
)
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 13 |
+
|
| 14 |
+
@spaces.GPU
|
| 15 |
+
def generate(prompt, history):
|
| 16 |
+
messages = [
|
| 17 |
+
{"role": "system", "content": "You are Zurich, a 7 billion parameter Large Language model built on the Qwen 2.5 7B model developed by Alibaba Cloud, and fine-tuned by Ruben Roy. You have been fine-tuned with the GammaCorpus v2 dataset, a dataset filled with structured and filtered multi-turn conversations and was also created by Ruben Roy. You are a helpful assistant."},
|
| 18 |
+
{"role": "user", "content": prompt}
|
| 19 |
+
]
|
| 20 |
+
text = tokenizer.apply_chat_template(
|
| 21 |
+
messages,
|
| 22 |
+
tokenize=False,
|
| 23 |
+
add_generation_prompt=True
|
| 24 |
+
)
|
| 25 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 26 |
+
generated_ids = model.generate(
|
| 27 |
+
**model_inputs,
|
| 28 |
+
max_new_tokens=512
|
| 29 |
+
)
|
| 30 |
+
generated_ids = [
|
| 31 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 32 |
+
]
|
| 33 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 34 |
+
return response
|
| 35 |
+
|
| 36 |
+
TITLE_HTML = """
|
| 37 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
| 38 |
+
<style>
|
| 39 |
+
.model-btn {
|
| 40 |
+
background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
|
| 41 |
+
color: white !important;
|
| 42 |
+
padding: 0.75rem 1rem;
|
| 43 |
+
border-radius: 0.5rem;
|
| 44 |
+
text-decoration: none !important;
|
| 45 |
+
font-weight: 500;
|
| 46 |
+
transition: all 0.2s ease;
|
| 47 |
+
font-size: 0.9rem;
|
| 48 |
+
display: flex;
|
| 49 |
+
align-items: center;
|
| 50 |
+
justify-content: center;
|
| 51 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
| 52 |
+
}
|
| 53 |
+
.model-btn:hover {
|
| 54 |
+
background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
|
| 55 |
+
box-shadow: 0 4px 6px rgba(0,0,0,0.2);
|
| 56 |
+
}
|
| 57 |
+
.model-section {
|
| 58 |
+
flex: 1;
|
| 59 |
+
max-width: 450px;
|
| 60 |
+
background: rgba(255, 255, 255, 0.05);
|
| 61 |
+
padding: 1.5rem;
|
| 62 |
+
border-radius: 1rem;
|
| 63 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 64 |
+
backdrop-filter: blur(10px);
|
| 65 |
+
transition: all 0.3s ease;
|
| 66 |
+
}
|
| 67 |
+
.info-link {
|
| 68 |
+
color: #60a5fa;
|
| 69 |
+
text-decoration: none;
|
| 70 |
+
transition: color 0.2s ease;
|
| 71 |
+
}
|
| 72 |
+
.info-link:hover {
|
| 73 |
+
color: #93c5fd;
|
| 74 |
+
text-decoration: underline;
|
| 75 |
+
}
|
| 76 |
+
.info-section {
|
| 77 |
+
margin-top: 0.5rem;
|
| 78 |
+
font-size: 0.9rem;
|
| 79 |
+
color: #94a3b8;
|
| 80 |
+
}
|
| 81 |
+
</style>
|
| 82 |
+
|
| 83 |
+
<div style="background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); padding: 1.5rem; border-radius: 1.5rem; text-align: center; margin: 1rem auto; max-width: 1200px; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);">
|
| 84 |
+
<div style="margin-bottom: 1.5rem;">
|
| 85 |
+
<div style="display: flex; align-items: center; justify-content: center; gap: 1rem;">
|
| 86 |
+
<h1 style="font-size: 2.5rem; font-weight: 800; margin: 0; background: linear-gradient(135deg, #60a5fa 0%, #93c5fd 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">Zurich</h1>
|
| 87 |
+
<div style="width: 2px; height: 2.5rem; background: linear-gradient(180deg, #3b82f6 0%, #60a5fa 100%);"></div>
|
| 88 |
+
<p style="font-size: 1.25rem; color: #94a3b8; margin: 0;">GammaCorpus v2-5m</p>
|
| 89 |
+
</div>
|
| 90 |
+
<div class="info-section">
|
| 91 |
+
<span>Fine-tuned from <a href="https://huggingface.co/Qwen/Qwen2.5-7B-Instruct" class="info-link">Qwen 2.5 7B Instruct</a> | Model: <a href="https://huggingface.co/rubenroy/Zurich-7b-GCv2-5m" class="info-link">Zurich-7b-GCv2-5m</a> | Training Dataset: <a href="https://huggingface.co/datasets/rubenroy/GammaCorpus-v2-5m" class="info-link">GammaCorpus v2 5m</a></span>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
|
| 95 |
+
<div style="display: flex; gap: 1.5rem; justify-content: center;">
|
| 96 |
+
<div class="model-section">
|
| 97 |
+
<h2 style="font-size: 1.25rem; color: #e2e8f0; margin-bottom: 1rem; margin-top: 1px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 0.7rem;">
|
| 98 |
+
<i class="fas fa-brain"></i>
|
| 99 |
+
7B Models
|
| 100 |
+
</h2>
|
| 101 |
+
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;">
|
| 102 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-7B-GCv2-5m" class="model-btn">Zurich 7B GCv2 5m</a>
|
| 103 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-7B-GCv2-1m" class="model-btn">Zurich 7B GCv2 1m</a>
|
| 104 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-7B-GCv2-500k" class="model-btn">Zurich 7B GCv2 500k</a>
|
| 105 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-7B-GCv2-100k" class="model-btn">Zurich 7B GCv2 100k</a>
|
| 106 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-7B-GCv2-50k" class="model-btn">Zurich 7B GCv2 50k</a>
|
| 107 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-7B-GCv2-10k" class="model-btn">Zurich 7B GCv2 10k</a>
|
| 108 |
+
</div>
|
| 109 |
+
</div>
|
| 110 |
+
<div class="model-section">
|
| 111 |
+
<h2 style="font-size: 1.25rem; color: #e2e8f0; margin-bottom: 1rem; margin-top: 1px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 0.7rem;">
|
| 112 |
+
<i class="fas fa-rocket"></i>
|
| 113 |
+
14B Models
|
| 114 |
+
</h2>
|
| 115 |
+
<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;">
|
| 116 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-14B-GCv2-5m" class="model-btn">Zurich 14B GCv2 5m</a>
|
| 117 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-14B-GCv2-1m" class="model-btn">Zurich 14B GCv2 1m</a>
|
| 118 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-14B-GCv2-500k" class="model-btn">Zurich 14B GCv2 500k</a>
|
| 119 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-14B-GCv2-100k" class="model-btn">Zurich 14B GCv2 100k</a>
|
| 120 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-14B-GCv2-50k" class="model-btn">Zurich 14B GCv2 50k</a>
|
| 121 |
+
<a href="https://huggingface.co/spaces/rubenroy/Zurich-14B-GCv2-10k" class="model-btn">Zurich 14B GCv2 10k</a>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
</div>
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
with gr.Blocks() as demo:
|
| 129 |
+
gr.HTML(TITLE_HTML)
|
| 130 |
+
chat_interface = gr.ChatInterface(
|
| 131 |
+
fn=generate,
|
| 132 |
+
)
|
| 133 |
+
demo.launch(share=True)
|