Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,16 +11,17 @@ from huggingface_hub import HfApi
|
|
11 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
-
# Load
|
15 |
-
MODEL_NAME = "
|
16 |
logger.info(f"Loading model: {MODEL_NAME} (CPU mode)")
|
17 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME
|
18 |
-
|
|
|
19 |
|
20 |
-
# Function to process text with
|
21 |
def process_text_with_model(text):
|
22 |
-
logger.info("Processing text with
|
23 |
-
inputs = tokenizer(text, return_tensors="pt"
|
24 |
outputs = model.generate(**inputs, max_length=200)
|
25 |
processed_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
26 |
return processed_text
|
@@ -46,7 +47,7 @@ def generate_and_upload(text):
|
|
46 |
|
47 |
logger.info(f"Received text input: {text}")
|
48 |
|
49 |
-
# Process text with
|
50 |
processed_text = process_text_with_model(text)
|
51 |
logger.info(f"Processed text: {processed_text}")
|
52 |
|
@@ -85,8 +86,8 @@ def generate_and_upload(text):
|
|
85 |
with gr.Blocks() as demo:
|
86 |
with gr.Tab("About"):
|
87 |
gr.Markdown("""
|
88 |
-
# Text Processor with
|
89 |
-
- Processes text with
|
90 |
- Converts output to JSON
|
91 |
- Uploads to Hugging Face
|
92 |
|
|
|
11 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
12 |
logger = logging.getLogger(__name__)
|
13 |
|
14 |
+
# Load GPT-2 model and tokenizer
|
15 |
+
MODEL_NAME = "gpt2"
|
16 |
logger.info(f"Loading model: {MODEL_NAME} (CPU mode)")
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
18 |
+
tokenizer.pad_token = tokenizer.eos_token # GPT-2 không có padding token, nên dùng eos_token
|
19 |
+
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
|
20 |
|
21 |
+
# Function to process text with GPT-2
|
22 |
def process_text_with_model(text):
|
23 |
+
logger.info("Processing text with GPT-2 model (CPU)...")
|
24 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
25 |
outputs = model.generate(**inputs, max_length=200)
|
26 |
processed_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
27 |
return processed_text
|
|
|
47 |
|
48 |
logger.info(f"Received text input: {text}")
|
49 |
|
50 |
+
# Process text with GPT-2
|
51 |
processed_text = process_text_with_model(text)
|
52 |
logger.info(f"Processed text: {processed_text}")
|
53 |
|
|
|
86 |
with gr.Blocks() as demo:
|
87 |
with gr.Tab("About"):
|
88 |
gr.Markdown("""
|
89 |
+
# Text Processor with GPT-2 (CPU)
|
90 |
+
- Processes text with GPT-2 Transformer
|
91 |
- Converts output to JSON
|
92 |
- Uploads to Hugging Face
|
93 |
|