Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,7 +86,7 @@ capy_proposal = read_pdf(file_path)
|
|
| 86 |
# input = read_pdf(file_path)
|
| 87 |
|
| 88 |
# Function to grade the essay using GPT-4
|
| 89 |
-
def grade_essay(
|
| 90 |
# Sample prompt for grading using GPT-4
|
| 91 |
template = f"""
|
| 92 |
|
|
@@ -175,17 +175,39 @@ def main():
|
|
| 175 |
# Grading button
|
| 176 |
if st.button("Grade Proposal"):
|
| 177 |
if new_file:
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
# st.dataframe(df)
|
| 191 |
|
|
|
|
| 86 |
# input = read_pdf(file_path)
|
| 87 |
|
| 88 |
# Function to grade the essay using GPT-4
|
| 89 |
+
def grade_essay(input):
|
| 90 |
# Sample prompt for grading using GPT-4
|
| 91 |
template = f"""
|
| 92 |
|
|
|
|
| 175 |
# Grading button
|
| 176 |
if st.button("Grade Proposal"):
|
| 177 |
if new_file:
|
| 178 |
+
result = grade_essay(input=new_file)
|
| 179 |
+
|
| 180 |
+
st.write("Result from grade_essay:", result)
|
| 181 |
+
st.write("Type of result:", type(result))
|
| 182 |
+
|
| 183 |
+
if result:
|
| 184 |
+
try:
|
| 185 |
+
# Case 1: if it's a string, assume it's a JSON string
|
| 186 |
+
if isinstance(result, str):
|
| 187 |
+
df = pd.read_json(result)
|
| 188 |
+
|
| 189 |
+
# Case 2: if it's already a dict or list of dicts, use DataFrame directly
|
| 190 |
+
elif isinstance(result, (dict, list)):
|
| 191 |
+
df = pd.DataFrame(result)
|
| 192 |
+
|
| 193 |
+
else:
|
| 194 |
+
st.error("Unexpected return type from grade_essay.")
|
| 195 |
+
|
| 196 |
+
except ValueError as e:
|
| 197 |
+
st.error(f"Error parsing JSON: {e}")
|
| 198 |
+
else:
|
| 199 |
+
st.error("No data returned from grade_essay.")
|
| 200 |
+
# final_feedback = grade_essay(input = new_file)
|
| 201 |
+
# final_feedback = final_feedback.replace("\n", "")
|
| 202 |
+
# df = pd.read_json(str(grade_essay(input = new_file)))
|
| 203 |
+
# df = df.T
|
| 204 |
+
# # Store results in session state
|
| 205 |
+
# st.session_state.results.append({
|
| 206 |
+
# 'Feedback': df
|
| 207 |
+
# })
|
| 208 |
+
|
| 209 |
+
# st.write("Feedback:")
|
| 210 |
+
# st.dataframe(df)
|
| 211 |
|
| 212 |
# st.dataframe(df)
|
| 213 |
|