Spaces:
Sleeping
Sleeping
Update app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import gradio as grfrom transformers import pipelineimport reimport json# Загружаем Phi-3 (автоматически выберет CPU/GPU)pipe = pipeline("text-generation",model="microsoft/Phi-3-mini-4k-instruct",device_map="auto",torch_dtype="auto")def extract_tasks(text):prompt = f"""<|system|>You are a task extraction assistant. Extract all tasks as a JSON array.Each task must have: action, context, details, responsible, deadline, references.Output ONLY valid JSON array, no explanations.Example: [{"action": "send contract", "context": "client #1", "details": "send and track", "responsible": "", "deadline": "", "references": []}]<|end|><|user|>Text: {text}<|end|><|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']# Ищем JSON в ответеjson_match = re.search(r'\[.*\]', result, re.DOTALL)if json_match:tasks = json.loads(json_match.group(0))return taskselse:return "Не удалось найти JSON в ответе модели."except Exception as e:return f"Ошибка: {str(e)}"# UIiface = gr.Interface(fn=extract_tasks,inputs=gr.Textbox(label="Транскрипт встречи",placeholder="Добрый день, коллеги. Нужно отправить договор заказчику номер один...",lines=6),outputs=gr.JSON(label="Задачи (JSON)"),title="AI Task Extractor с Phi-3",description="Вставь текст → получи задачи в JSON",examples=[["Добрый день, коллеги. Нужно отправить договор заказчику номер один и отслеживать статус. Составить счёт. Коллеги — предоставить документы."]])iface.launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import gradio as grfrom transformers import pipelineimport 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']# Ищем JSONjson_match = re.search(r'\[.*\]', result, re.DOTALL)if json_match:tasks = json.loads(json_match.group(0))return taskselse:return "Не удалось найти JSON в ответе модели."except Exception as e:return f"Ошибка: {str(e)}"# UIiface = gr.Interface(fn=extract_tasks,inputs=gr.Textbox(label="Транскрипт встречи",placeholder="Добрый день, коллеги. Нужно отправить договор заказчику номер один...",lines=6),outputs=gr.JSON(label="Задачи (JSON)"),title="AI Task Extractor с Phi-3",description="Вставь текст → получи задачи в JSON",examples=[["Добрый день, коллеги. Нужно отправить договор заказчику номер один и отслеживать статус. Составить счёт. Коллеги — предоставить документы."]])iface.launch()
app.py+52-60