-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.py
More file actions
57 lines (44 loc) · 1.73 KB
/
event.py
File metadata and controls
57 lines (44 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pandas as pd
import os
import LLM_base as lm
# Load summarizer model
summarizer = lm.FaSummarizationPipeline()
def is_file_too_large(file_path, max_size_mb=5):
"""Check if file size is larger than max_size_mb"""
return os.path.getsize(file_path) / (1024 * 1024) > max_size_mb
def read_file(file_path):
"""Read CSV or XLSX file"""
try:
if file_path.endswith('.csv'):
return pd.read_csv(file_path)
elif file_path.endswith('.xlsx'):
return pd.read_excel(file_path)
else:
raise ValueError("Unsupported file format. Only CSV and XLSX are supported.")
except Exception as e:
return f"Error in reading file: {e}"
def generate_summary(text):
"""Generate summary for given text"""
try:
summary = summarizer.summarize(text,input_max_length=1024,model_max_length=256)
return summary
except Exception as e:
return f"Error in generating summary: {e}"
def process_event_file(file_path):
"""Process event file and return summary"""
if is_file_too_large(file_path):
return "File size is too large. Maximum allowed size is 5 MB."
df = read_file(file_path)
if isinstance(df, str): # If error occurred
return df
# Convert dataframe to text
prefix = 'متن داده شده حاصل استخراج اطلاعات از سند داده شده است:'
text = prefix + " ".join(df.astype(str).values.flatten())
# Generate summary
summary = generate_summary(text)
return summary
# Usage example
# file_path = "OfficebazWorldcup2022.xlsx"
# result = process_event_file(file_path)
# print(result)
#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