shahzaib201 commited on
Commit
8bcd317
1 Parent(s): ef93e92

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +17 -22
main.py CHANGED
@@ -1,27 +1,22 @@
1
- from ctransformers import AutoModelForCausalLM
2
- from fastapi import FastAPI, Form
3
  from pydantic import BaseModel
 
4
 
5
- #Model loading
6
- llm = AutoModelForCausalLM.from_pretrained("TherapyBeagle-11B-v1-Q2_K.gguf",
7
- model_type='llama',
8
- max_new_tokens = 1096,
9
- threads = 3,
10
- )
11
-
12
 
13
- #Pydantic object
14
- class validation(BaseModel):
15
- prompt: str
16
-
17
- #Fast API
18
  app = FastAPI()
19
 
20
- #Zephyr completion
21
- @app.post("/llm_on_cpu")
22
- async def stream(item: validation):
23
- system_prompt = 'Below is an instruction that describes a task. Write a response that appropriately completes the request.'
24
- E_INST = "</s>"
25
- user, assistant = "<|user|>", "<|assistant|>"
26
- prompt = f"{system_prompt}{E_INST}\n{user}\n{item.prompt.strip()}{E_INST}\n{assistant}\n"
27
- return llm(prompt)
 
1
+ from fastapi import FastAPI
 
2
  from pydantic import BaseModel
3
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
4
 
5
+ # Load the depression detection model
6
+ tokenizer = AutoTokenizer.from_pretrained("paulagarciaserrano/roberta-depression-detection")
7
+ model = AutoModelForSequenceClassification.from_pretrained("paulagarciaserrano/roberta-depression-detection")
8
+ depression_pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
 
 
 
9
 
10
+ # Pydantic object for validation
11
+ class DepressionInput(BaseModel):
12
+ text: str
13
+
14
+ # FastAPI app
15
  app = FastAPI()
16
 
17
+ # Endpoint for depression detection
18
+ @app.post("/depression_detection")
19
+ async def detect_depression(item: DepressionInput):
20
+ result = depression_pipe(item.text)
21
+ return result
22
+