rairo commited on
Commit
9cda0fc
·
verified ·
1 Parent(s): 0f02977

Update stories.py

Browse files
Files changed (1) hide show
  1. stories.py +24 -5
stories.py CHANGED
@@ -85,11 +85,6 @@ class FlaskResponse(ResponseParser):
85
  # For non-image responses, simply return the value as a string.
86
  return str(result["value"])
87
 
88
-
89
-
90
-
91
-
92
-
93
  # Pandasai gemini
94
  llm1 = ChatGoogleGenerativeAI(
95
  model="gemini-2.0-flash-thinking-exp",
@@ -135,6 +130,30 @@ def get_pdf_text(pdf_file):
135
  text = text[:MAX_CHARACTERS]
136
  return text
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
 
139
  # -----------------------
140
  # Audio Transcription
 
85
  # For non-image responses, simply return the value as a string.
86
  return str(result["value"])
87
 
 
 
 
 
 
88
  # Pandasai gemini
89
  llm1 = ChatGoogleGenerativeAI(
90
  model="gemini-2.0-flash-thinking-exp",
 
130
  text = text[:MAX_CHARACTERS]
131
  return text
132
 
133
+ def get_df(uploaded_file, ext):
134
+ """
135
+ Reads an uploaded file into a pandas DataFrame if the extension is csv, xlsx, or xls.
136
+
137
+ Args:
138
+ uploaded_file: The uploaded file object.
139
+ ext (str): The extension of the uploaded file.
140
+
141
+ Returns:
142
+ pandas.DataFrame: The DataFrame if the file is successfully read, otherwise None.
143
+ """
144
+ if ext in ["csv", "xlsx", "xls"]:
145
+ try:
146
+ if ext == "csv":
147
+ df = pd.read_csv(uploaded_file)
148
+ else:
149
+ df = pd.read_excel(uploaded_file)
150
+ return df
151
+ except Exception as e:
152
+ print(f"Error reading file: {e}")
153
+ return None
154
+ else:
155
+ print(f"Unsupported file extension: {ext}. Please upload a csv, xlsx, or xls file.")
156
+ return None
157
 
158
  # -----------------------
159
  # Audio Transcription