Instructions to use Ataraxia009/AnxietyModelFinal-Merged with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ataraxia009/AnxietyModelFinal-Merged with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Ataraxia009/AnxietyModelFinal-Merged") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Ataraxia009/AnxietyModelFinal-Merged") model = AutoModelForCausalLM.from_pretrained("Ataraxia009/AnxietyModelFinal-Merged", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Ataraxia009/AnxietyModelFinal-Merged with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ataraxia009/AnxietyModelFinal-Merged" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ataraxia009/AnxietyModelFinal-Merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Ataraxia009/AnxietyModelFinal-Merged
- SGLang
How to use Ataraxia009/AnxietyModelFinal-Merged with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Ataraxia009/AnxietyModelFinal-Merged" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ataraxia009/AnxietyModelFinal-Merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Ataraxia009/AnxietyModelFinal-Merged" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ataraxia009/AnxietyModelFinal-Merged", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Ataraxia009/AnxietyModelFinal-Merged with Docker Model Runner:
docker model run hf.co/Ataraxia009/AnxietyModelFinal-Merged
File size: 4,536 Bytes
641eed3 c72b4ed 641eed3 595788e 641eed3 1fe53f2 641eed3 1fe53f2 641eed3 1fe53f2 641eed3 1fe53f2 abf9374 641eed3 abf9374 641eed3 abf9374 641eed3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | from typing import Any, Dict, List
import torch
import json
import transformers
import bitsandbytes
from transformers import AutoModelForCausalLM, AutoTokenizer
dtype = torch.bfloat16 if torch.cuda.get_device_capability()[0] == 8 else torch.float16
class EndpointHandler:
def __init__(self, path=""):
print("ANSHAY calling EndpointHandler __init__")
self.tokenizer = AutoTokenizer.from_pretrained(path, trust_remote_code=True)
self.model = AutoModelForCausalLM.from_pretrained(
path,
return_dict=True,
device_map="auto",
load_in_8bit=True,
torch_dtype=dtype,
trust_remote_code=True,
)
print("ANSHAY got model and tokenizer")
print(self.model)
print(self.tokenizer)
generation_config = self.model.generation_config
generation_config.max_new_tokens = 3
generation_config.temperature = 0.1
generation_config.pad_token_id = self.tokenizer.eos_token_id
generation_config.eos_token_id = self.tokenizer.eos_token_id
self.generation_config = generation_config
self.pipeline = transformers.pipeline(
"text-generation", model=self.model, tokenizer=self.tokenizer
)
print("ANSHAY got pipeline")
print(self.pipeline)
def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]:
print("ANSHAY in __call__ of handler")
print("ANSHAY printing data:")
print(data)
input_string = data.pop("inputs");
print("ANSHAY printing input_string:")
print(input_string)
input_dict = json.loads(input_string)
print("ANSHAY printing input_dict:")
print(input_dict)
gender = input_dict["gender"]
age = input_dict["age"]
occupation = input_dict["occupation"]
sleep_hours = input_dict["sleep_hours"]
physical_activity = input_dict["physical_activity"]
caffiene_intake = input_dict["caffiene_intake"]
alcohol_consumption = input_dict["alcohol_consumption"]
smoking = input_dict["smoking"]
family_anxiety = input_dict["family_anxiety"]
stress_level = input_dict["stress_level"]
heart_rate = input_dict["heart_rate"]
breathing_rate = input_dict["breathing_rate"]
sweating_level = input_dict["sweating_level"]
dizziness = input_dict["dizziness"]
medication = input_dict["medication"]
therapy_sessions = input_dict["therapy_sessions"]
recent_life_event = input_dict["recent_life_event"]
diet_quality = input_dict["diet_quality"]
chat_formatted = [{
"role": "system",
"content": "You are an anxiety calculating bot. You help people rate their anxiety on a scall of 1-10, after understanding their current lifestyle.",
},
{
"role": "user",
"content": f"Here are my details:\nGender:{gender}\nAge:{age}\nOccupation:{occupation}\nSleep Hours:{sleep_hours}\nPhysical Activity (hrs/week):{physical_activity}\nCaffeine Intake (mg/day):{caffiene_intake}\nAlcohol Consumption (drinks/week):{alcohol_consumption}\nSmoking:{smoking}\nFamily History of Anxiety:{family_anxiety}\nStress Level (1-10):{stress_level}\nHeart Rate (bpm):{heart_rate}\nBreathing Rate (breaths/min):{breathing_rate}\nSweating Level (1-5):{sweating_level}\nDizziness:{dizziness}\nMedication:{medication}\nTherapy Sessions (per month):{therapy_sessions}\nRecent Major Life Event:{recent_life_event}\nDiet Quality (1-10):{diet_quality}"
},
{
"role": "assistant",
"content": f"Anxiety Rating:"
}]
print("ANSHAY printing final chat formatted:")
print(chat_formatted)
chat_template_applied = self.tokenizer.apply_chat_template(chat_formatted, tokenize=False, continue_final_message=True)
print("ANSHAY printing final chat_template_applied:")
print(chat_template_applied)
result = self.pipeline(chat_template_applied, generation_config=self.generation_config)
print("ANSHAY printing final result:")
print(result)
generated_text = result[0]['generated_text']
print("ANSHAY printing generated_text:")
print(generated_text)
anxiety_rating = generated_text[-3:]
print("ANSHAY printing anxiety_rating:")
print(anxiety_rating)
return anxiety_rating |