Spaces:
Sleeping
Sleeping
Update app.py
Browse files12234678910111256141516171819202122232425262728293031323334353637383940417891011121314151617181920212223242526274647484950282952533031325533343536593738import gradio as grfrom transformers import pipelineimport reimport json
# ЛЁГКАЯ МОДЕЛЬ — РАБОТАЕТ НА CPUpipe = pipeline( "text-generation", model="distilgpt2", device_map="cpu")
# САМАЯ ПРОСТАЯ МОДЕЛЬ — РАБОТАЕТ ВЕЗДЕdef extract_tasks(text): prompt = f"""Extract all tasks from the text as a JSON array.Each task must have: action, context, details, responsible, deadline, references.Output ONLY the JSON, no extra text.
Text: {text}
JSON:"""
try: result = pipe( prompt, max_new_tokens=256, temperature=0.1, do_sample=True, truncation=True )[0]['generated_text']
# Ищем JSON после "JSON:" json_part = result.split("JSON:")[-1].strip() json_match = re.search(r'\[.*\]', json_part, re.DOTALL)
if json_match: tasks = json.loads(json_match.group(0)) return tasks else: return {"error": "JSON not found", "raw_output": result[-200:]} except Exception as e: return {"error": str(e)} # Ручной парсинг (без LLM) — 100% работает lines = [l.strip() for l in text.split('.') if l.strip()] tasks = [] for line in lines: if any(word in line.lower() for word in ['нужно', 'отправить', 'составить', 'предоставить', 'сделать']): action = line.split(' ', 1)[1] if ' ' in line else line tasks.append({ "action": action, "context": "из встречи", "details": line, "responsible": "", "deadline": "", "references": [] }) return tasks if tasks else [{"action": "ничего не найдено", "details": text}]
# UIiface = gr.Interface( fn=extract_tasks, inputs=gr.Textbox( label="Транскрипт встречи", placeholder="Добрый день, коллеги. Нужно отправить договор заказчику номер один...", lines=6 ), inputs=gr.Textbox(label="Транскрипт", lines=5), outputs=gr.JSON(label="Задачи"), title="AI Task Extractor (быстро!)", description="Работает мгновенно на бесплатном CPU", title="Task Extractor (без AI)", description="Работает мгновенно. Без GPU. Без ошибок.", examples=[ ["Добрый день, коллеги. Нужно отправить договор заказчику номер один и отслеживать статус. Составить счёт. Коллеги — предоставить документы."] ["Добрый день, коллеги. Нужно отправить договор. Составить счёт. Предоставить документы."] ])
iface.launch()# КРИТИЧНО: server_name="0.0.0.0"iface.launch(server_name="0.0.0.0", server_port=7860)app.py+24-45