Spaces:
Build error
Build error
| import os | |
| from transformers import pipeline | |
| from upload.data import process_uploaded_file, extract_text_from_pdf, extract_key_info | |
| summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
| chatbot = pipeline("conversational", model="microsoft/DialoGPT-medium") | |
| def summarize_text(text: str) -> str: | |
| summary = summarizer(text, max_length=50, min_length=10, do_sample=False) | |
| return summary[0]['summary_text'] | |
| def chat_with_document(text: str, user_input: str) -> str: | |
| from transformers import Conversation | |
| conversation = Conversation(user_input) | |
| response = chatbot([conversation], text_context=text) | |
| return response.generated_responses[-1] | |
| def process_and_analyze(file_path: str): | |
| data = process_uploaded_file(file_path) | |
| text = extract_text_from_pdf(file_path) | |
| summary = summarize_text(text) | |
| print(f"Tóm tắt: {summary}") | |
| while True: | |
| user_input = input("Nhập câu hỏi (hoặc 'exit' để thoát): ") | |
| if user_input.lower() == 'exit': | |
| break | |
| response = chat_with_document(text, user_input) | |
| print(f"Trả lời: {response}") |