Spaces:
Sleeping
Sleeping
Download app.py from Panjuldir/Server-TestQ: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/Panjuldir/Server-TestQ/resolve/main/app.py
- Command line
-
hf download hf://spaces/Panjuldir/Server-TestQ/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Panjuldir/Server-TestQ/resolve/main/app.py
1.45 kB
| import gradio as gr | |
| import spaces | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| # Kita pakai Dolphin-Qwen2 (Uncensored Safetensors) | |
| model_id = "cognitivecomputations/dolphin-2.9.2-qwen2-7b" | |
| tokenizer = AutoTokenizer.from_pretrained(model_id) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| model_id, | |
| torch_dtype=torch.bfloat16, | |
| device_map="auto" | |
| ) | |
| def generate_response(message, history): | |
| messages = [] | |
| for user_msg, ai_msg in history: | |
| messages.append({"role": "user", "content": user_msg}) | |
| messages.append({"role": "assistant", "content": ai_msg}) | |
| messages.append({"role": "user", "content": message}) | |
| text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) | |
| inputs = tokenizer([text], return_tensors="pt").to(model.device) | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=512, | |
| temperature=0.7, | |
| top_p=0.9, | |
| do_sample=True, | |
| ) | |
| input_len = inputs["input_ids"].shape[1] | |
| response = tokenizer.decode(outputs[0][input_len:], skip_special_tokens=True) | |
| return response | |
| demo = gr.ChatInterface( | |
| fn=generate_response, | |
| title="🚀 Dolphin-Qwen 7B (NVIDIA A100 ZeroGPU)", | |
| description="Server AI Uncensored (Tanpa Batasan)! Punya API bawaan gratis yang siap disambungkan.", | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |