Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,7 +46,6 @@ tokenizer_info = xgr.TokenizerInfo.from_huggingface(
|
|
| 46 |
|
| 47 |
grammar_compiler = xgr.GrammarCompiler(tokenizer_info)
|
| 48 |
compiled_grammar = grammar_compiler.compile_json_schema(Person)
|
| 49 |
-
xgr_logits_processor = xgr.contrib.hf.LogitsProcessor(compiled_grammar)
|
| 50 |
|
| 51 |
default_value = "A 57-year-old male presented with fever (38.9Β°C), chest pain, cough, and progressive dyspnea. The patient exhibited tachypnea (34 breaths/min) and tachycardia (134 bpm). Auscultation revealed decreased breath sounds in both lung bases, with crackles on the left. A chest X-ray revealed bilateral pleural opacities and enlargement of the cardiac silhouette ( A). Echocardiography showed moderate pericardial effusion affecting the entire cardiac silhouette. Pericardiocentesis yielded 250 mL of exudative fluid. A CT scan of the chest showed pneumonia in the left lower lobe, bilateral pleural effusion, and moderate pericardial effusion ( B). Thoracentesis was performed and yielded 1,050 mL of exudative fluid. Laboratory tests yielded the following data: white blood cell count, 11.78 Γ 109 cells/L (84.3% neutrophils, 4.3% lymphocytes, and 9.1% monocytes); platelet count, 512 Γ 109/L; serum C-reactive protein, 31.27 mg/dL; serum creatinine, 0.94 mg/dL; serum sodium, 133 mEq/L; and serum potassium, 3.72 mEq/L. Examination of the pleural fluid showed a pH of 7.16, a glucose level of 4.5 mg/dL, proteins at 49.1 g/L, and an LDH content of 1,385 U/L. A urinary pneumococcal antigen test was positive. Pleural fluid culture was positive for S. pneumoniae. The patient was treated for four weeks with amoxicillin-clavulanate (2.2 g/8 h, i.v.) plus levofloxacin (500 mg twice a day), together with a nonsteroidal anti-inflammatory drug (ibuprofen, 800 mg/day), after which there was nearly complete resolution of the alterations seen on the chest X-ray and CT scan."
|
| 52 |
|
|
@@ -198,6 +197,10 @@ def summarize(
|
|
| 198 |
add_generation_prompt=True,
|
| 199 |
enable_thinking=False, # only relevant for qwen
|
| 200 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 203 |
generated_ids = model.generate(
|
|
|
|
| 46 |
|
| 47 |
grammar_compiler = xgr.GrammarCompiler(tokenizer_info)
|
| 48 |
compiled_grammar = grammar_compiler.compile_json_schema(Person)
|
|
|
|
| 49 |
|
| 50 |
default_value = "A 57-year-old male presented with fever (38.9Β°C), chest pain, cough, and progressive dyspnea. The patient exhibited tachypnea (34 breaths/min) and tachycardia (134 bpm). Auscultation revealed decreased breath sounds in both lung bases, with crackles on the left. A chest X-ray revealed bilateral pleural opacities and enlargement of the cardiac silhouette ( A). Echocardiography showed moderate pericardial effusion affecting the entire cardiac silhouette. Pericardiocentesis yielded 250 mL of exudative fluid. A CT scan of the chest showed pneumonia in the left lower lobe, bilateral pleural effusion, and moderate pericardial effusion ( B). Thoracentesis was performed and yielded 1,050 mL of exudative fluid. Laboratory tests yielded the following data: white blood cell count, 11.78 Γ 109 cells/L (84.3% neutrophils, 4.3% lymphocytes, and 9.1% monocytes); platelet count, 512 Γ 109/L; serum C-reactive protein, 31.27 mg/dL; serum creatinine, 0.94 mg/dL; serum sodium, 133 mEq/L; and serum potassium, 3.72 mEq/L. Examination of the pleural fluid showed a pH of 7.16, a glucose level of 4.5 mg/dL, proteins at 49.1 g/L, and an LDH content of 1,385 U/L. A urinary pneumococcal antigen test was positive. Pleural fluid culture was positive for S. pneumoniae. The patient was treated for four weeks with amoxicillin-clavulanate (2.2 g/8 h, i.v.) plus levofloxacin (500 mg twice a day), together with a nonsteroidal anti-inflammatory drug (ibuprofen, 800 mg/day), after which there was nearly complete resolution of the alterations seen on the chest X-ray and CT scan."
|
| 51 |
|
|
|
|
| 197 |
add_generation_prompt=True,
|
| 198 |
enable_thinking=False, # only relevant for qwen
|
| 199 |
)
|
| 200 |
+
|
| 201 |
+
# We cannot reset here because __call__ is not invoked when stop token is sampled.
|
| 202 |
+
# Therefore, each `generate()` call needs to instantiate an LogitsProcessor.
|
| 203 |
+
xgr_logits_processor = xgr.contrib.hf.LogitsProcessor(compiled_grammar)
|
| 204 |
|
| 205 |
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 206 |
generated_ids = model.generate(
|