Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines34567891011121314151617181920212223242526272 unmodified lines303132333435366 unmodified lines43444546474849502 unmodified linesimport reimport json# Загружаем Phi-3pipe = pipeline("text-generation",model="microsoft/Phi-3-mini-4k-instruct",device_map="auto",torch_dtype="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|>'try:result = pipe(prompt,max_new_tokens=512,temperature=0.1,do_sample=True,pad_token_id=pipe.tokenizer.eos_token_id)[0]['generated_text']# Ищем JSON2 unmodified linestasks = json.loads(json_match.group(0))return taskselse:return "Не удалось найти JSON в ответе модели."except Exception as e:return f"Ошибка: {str(e)}"6 unmodified lineslines=6),outputs=gr.JSON(label="Задачи (JSON)"),title="AI Task Extractor с Phi-3",description="Вставь текст → получи задачи в JSON",examples=[["Добрый день, коллеги. Нужно отправить договор заказчику номер один и отслеживать статус. Составить счёт. Коллеги — предоставить документы."]]2 unmodified lines34567891011121314151617181920212223242 unmodified lines272829303132336 unmodified lines40414243444546472 unmodified linesimport reimport json# ЛЁГКАЯ МОДЕЛЬ (работает на CPU Basic)pipe = pipeline("text-generation",model="distilgpt2",device_map="auto")def extract_tasks(text):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=256,temperature=0.1,do_sample=True)[0]['generated_text']# Ищем JSON2 unmodified linestasks = json.loads(json_match.group(0))return taskselse:return "JSON не найден. Модель дала: " + result[:200]except Exception as e:return f"Ошибка: {str(e)}"6 unmodified lineslines=6),outputs=gr.JSON(label="Задачи (JSON)"),title="AI Task Extractor (distilgpt2)",description="Работает мгновенно!",examples=[["Добрый день, коллеги. Нужно отправить договор заказчику номер один и отслеживать статус. Составить счёт. Коллеги — предоставить документы."]]
app.py+9-12