Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines345667891011910111213151614151617182119202324212223242 unmodified lines27282933303132336 unmodified lines404142464743444546472 unmodified linesimport reimport json
# Загружаем Phi-3# ЛЁГКАЯ МОДЕЛЬ (работает на CPU Basic)pipe = pipeline( "text-generation", model="microsoft/Phi-3-mini-4k-instruct", device_map="auto", torch_dtype="auto" model="distilgpt2", device_map="auto")
def extract_tasks(text): # ИСПРАВЛЕНО: используем \""" для экранирования prompt = '<|system|>\nYou are a task extraction assistant. Extract all tasks as a JSON array.\nEach task must have: action, context, details, responsible, deadline, references.\nOutput ONLY valid JSON array, no explanations.\nExample: [{"action": "send contract", "context": "client #1", "details": "send and track", "responsible": "", "deadline": "", "references": []}]\n<|end|>\n<|user|>\nText: ' + text + '\n<|end|>\n<|assistant|>' prompt = f"Extract tasks as JSON array. Each task: action, context, details, responsible, deadline, references.\nText: {text}\nJSON:"
try: result = pipe( prompt, max_new_tokens=512, max_new_tokens=256, temperature=0.1, do_sample=True, pad_token_id=pipe.tokenizer.eos_token_id do_sample=True )[0]['generated_text']
# Ищем JSON2 unmodified lines tasks = json.loads(json_match.group(0)) return tasks else: return "Не удалось найти JSON в ответе модели." return "JSON не найден. Модель дала: " + result[:200] except Exception as e: return f"Ошибка: {str(e)}"
6 unmodified lines lines=6 ), outputs=gr.JSON(label="Задачи (JSON)"), title="AI Task Extractor с Phi-3", description="Вставь текст → получи задачи в JSON", title="AI Task Extractor (distilgpt2)", description="Работает мгновенно!", examples=[ ["Добрый день, коллеги. Нужно отправить договор заказчику номер один и отслеживать статус. Составить счёт. Коллеги — предоставить документы."] ]app.py+9-12