Spaces:
No application file
No application file
Keep @spaces.GPU decorator and optimize predict call
Browse files2 unmodified lines345678949 unmodified lines596061626364655 unmodified lines7172737274757677782 unmodified linesimport jsonimport numpy as npimport gradio as grimport spacesimport nltkfrom nltk.corpus import stopwordsfrom tensorflow.keras.models import Sequential49 unmodified lineselse: label_classes = [str(i) for i in range(7)]
@spaces.GPU(duration=25)def classify_text(raw_text: str): try: if not raw_text or not str(raw_text).strip():5 unmodified lines
seq = tokenizer.texts_to_sequences([cleaned]) padded = pad_sequences(seq, maxlen=MAX_LEN, padding="post", truncating="post") probs = model(padded, training=False).numpy()[0] padded = np.asarray(padded, dtype=np.int32) probs = model.predict(padded, verbose=0, batch_size=1)[0]
best_idx = int(np.argmax(probs)) best_label = label_classes[best_idx]app.py+4-1