ai-lover commited on
Commit
4c36940
·
verified ·
1 Parent(s): 0a9889e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -36,16 +36,23 @@ def generate_insights(df):
36
 
37
  return insights
38
 
39
- if df.empty:
40
- st.error("The uploaded dataset is empty. Please upload a valid dataset.")
41
- st.stop()
42
-
43
  # RAG setup using Hugging Face summarization
44
  def generate_query_summary(df, query):
45
  summarizer = pipeline("summarization")
46
  combined_text = " ".join(df.astype(str).apply(lambda x: " ".join(x), axis=1))
47
- result = summarizer(query + " " + combined_text, max_length=100, min_length=30, do_sample=False)
48
- return result[0]['summary_text']
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  # Streamlit app
51
  st.title("Employee Performance Dashboard")
@@ -77,4 +84,4 @@ if uploaded_file is not None:
77
  st.markdown("#### Summary")
78
  st.write(summary)
79
  else:
80
- st.info("Please upload a CSV file.")
 
36
 
37
  return insights
38
 
 
 
 
 
39
  # RAG setup using Hugging Face summarization
40
  def generate_query_summary(df, query):
41
  summarizer = pipeline("summarization")
42
  combined_text = " ".join(df.astype(str).apply(lambda x: " ".join(x), axis=1))
43
+
44
+ # Truncate text to avoid token limit issues
45
+ max_input_length = 1024
46
+ if len(combined_text) > max_input_length:
47
+ combined_text = combined_text[:max_input_length]
48
+
49
+ try:
50
+ result = summarizer(query + " " + combined_text, max_length=100, min_length=30, do_sample=False)
51
+ return result[0]['summary_text']
52
+ except IndexError:
53
+ return "Error: Unable to generate a summary. Ensure the query and data are valid."
54
+ except Exception as e:
55
+ return f"Error during summarization: {e}"
56
 
57
  # Streamlit app
58
  st.title("Employee Performance Dashboard")
 
84
  st.markdown("#### Summary")
85
  st.write(summary)
86
  else:
87
+ st.info("Please upload a CSV file.")