| import gradio as gr |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| import torch |
|
|
| |
| model_name = "jarradh/llama2_70b_chat_uncensored" |
|
|
| print("در حال بارگذاری مدل... ممکنه چند دقیقه طول بکشه") |
| tokenizer = AutoTokenizer.from_pretrained(model_name) |
| model = AutoModelForCausalLM.from_pretrained( |
| model_name, |
| torch_dtype=torch.float16, |
| device_map="auto" |
| ) |
|
|
| def chat_response(message, history): |
| |
| prompt = f"User: {message}\nAssistant:" |
| inputs = tokenizer(prompt, return_tensors="pt").to("cuda") |
| |
| |
| outputs = model.generate( |
| **inputs, |
| max_new_tokens=300, |
| temperature=0.7, |
| do_sample=True |
| ) |
| |
| |
| response = tokenizer.decode(outputs[0], skip_special_tokens=True) |
| |
| response = response.split("Assistant:")[-1].strip() |
| return response |
|
|
| |
| iface = gr.ChatInterface( |
| fn=chat_response, |
| title="🤖 چتبات بدون سانسور", |
| description="با Llama2 70B بدون فیلتر چت کن!" |
| ) |
|
|
| iface.launch(share=True) |