Update app.py
Browse files
app.py
CHANGED
@@ -2,15 +2,17 @@ import gradio as gr
|
|
2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
import torch
|
4 |
from pydantic import BaseModel
|
|
|
5 |
|
6 |
# Initialize FastAPI and Gradio
|
7 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
8 |
|
9 |
# Load the tokenizer and model once for use in both FastAPI and Gradio
|
10 |
tokenizer = T5Tokenizer.from_pretrained("alpeshsonar/lot-t5-small-filter", legacy=False)
|
11 |
-
model = T5ForConditionalGeneration.from_pretrained("alpeshsonar/lot-t5-small-filter").to(device)
|
12 |
|
13 |
# Gradio interface
|
|
|
14 |
def generate_text(input_text):
|
15 |
inputs = tokenizer.encode("Extract lots from given text.\n" + input_text, return_tensors="pt").to(device)
|
16 |
outputs = model.generate(inputs, max_new_tokens=1024)
|
|
|
2 |
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
import torch
|
4 |
from pydantic import BaseModel
|
5 |
+
import spaces
|
6 |
|
7 |
# Initialize FastAPI and Gradio
|
8 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
9 |
|
10 |
# Load the tokenizer and model once for use in both FastAPI and Gradio
|
11 |
tokenizer = T5Tokenizer.from_pretrained("alpeshsonar/lot-t5-small-filter", legacy=False)
|
12 |
+
model = T5ForConditionalGeneration.from_pretrained("alpeshsonar/lot-t5-small-filter", torch_dtype=torch.bfloat16).to(device)
|
13 |
|
14 |
# Gradio interface
|
15 |
+
@spaces.GPU(duration=360)
|
16 |
def generate_text(input_text):
|
17 |
inputs = tokenizer.encode("Extract lots from given text.\n" + input_text, return_tensors="pt").to(device)
|
18 |
outputs = model.generate(inputs, max_new_tokens=1024)
|