yashxx07 commited on
Commit
3a7dbda
·
verified ·
1 Parent(s): 54201c1

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -8
main.py CHANGED
@@ -4,23 +4,24 @@ from fastapi import FastAPI
4
  from pydantic import BaseModel
5
  import re
6
  import os
7
- from transformers import AutoModelWithLMHead, AutoTokenizer
 
8
 
9
  app = FastAPI()
10
 
 
11
 
 
 
 
12
 
13
- tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-summarize-news", use_fast=False)
14
- model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-summarize-news", use_fast=False)
15
 
16
- def summarize(text, max_length=150):
17
- input_ids = tokenizer.encode(text, return_tensors="pt", add_special_tokens=True)
18
 
19
- generated_ids = model.generate(input_ids=input_ids, num_beams=2, max_length=max_length, repetition_penalty=2.5, length_penalty=1.0, early_stopping=True)
20
 
21
- preds = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True) for g in generated_ids]
22
 
23
- return preds[0]
24
 
25
 
26
  @app.get("/")
 
4
  from pydantic import BaseModel
5
  import re
6
  import os
7
+ import transformers
8
+ import torch
9
 
10
  app = FastAPI()
11
 
12
+ model_id = "meta-llama/Meta-Llama-3-8B"
13
 
14
+ try:
15
+ pipeline = transformers.pipeline(
16
+ "text-generation", model=model_id, model_kwargs={"torch_dtype": torch.bfloat16}, device_map="auto")
17
 
18
+ print(pipeline("Hey how are you doing today?"))
 
19
 
20
+ except:
21
+ print("ERROR")
22
 
 
23
 
 
24
 
 
25
 
26
 
27
  @app.get("/")