Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +15 -2
Gradio_UI.py
CHANGED
@@ -26,7 +26,7 @@ from smolagents.utils import _is_package_available
|
|
26 |
|
27 |
|
28 |
|
29 |
-
|
30 |
import json
|
31 |
import pygsheets
|
32 |
import pandas as pd
|
@@ -56,7 +56,7 @@ df = pd.DataFrame()
|
|
56 |
df['name'] = ['John', 'Steve', 'Sarah']
|
57 |
|
58 |
#open the google spreadsheet (where 'PY to Gsheet Test' is the name of my sheet)
|
59 |
-
sh = gc.open('
|
60 |
|
61 |
#select the first sheet
|
62 |
wks = sh[0]
|
@@ -198,12 +198,25 @@ def stream_to_gradio(
|
|
198 |
):
|
199 |
yield message
|
200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
final_answer = step_log # Last log is the run's final_answer
|
202 |
final_answer = handle_agent_output_types(final_answer)
|
203 |
|
204 |
if isinstance(final_answer, AgentText):
|
205 |
formatted_final_answer = f"**Query:** {task}\n\n**Final answer:**\n{final_answer.to_string()}\n"
|
206 |
|
|
|
|
|
|
|
|
|
207 |
yield gr.ChatMessage(
|
208 |
role="assistant",
|
209 |
content=formatted_final_answer,
|
|
|
26 |
|
27 |
|
28 |
|
29 |
+
# Google Sheet connection
|
30 |
import json
|
31 |
import pygsheets
|
32 |
import pandas as pd
|
|
|
56 |
df['name'] = ['John', 'Steve', 'Sarah']
|
57 |
|
58 |
#open the google spreadsheet (where 'PY to Gsheet Test' is the name of my sheet)
|
59 |
+
sh = gc.open('LLM_evaluator')
|
60 |
|
61 |
#select the first sheet
|
62 |
wks = sh[0]
|
|
|
198 |
):
|
199 |
yield message
|
200 |
|
201 |
+
# Set up GoogleSheet
|
202 |
+
sheet_title = 'LLM_evaluator' # Ensure this matches the sheet's name
|
203 |
+
sh = gc.open(sheet_title)
|
204 |
+
worksheet = sh.sheet1 # Use the first sheet
|
205 |
+
def append_to_google_sheet(query, answer):
|
206 |
+
"""Append query and final answer to the Google Sheet."""
|
207 |
+
new_row = [query, answer]
|
208 |
+
worksheet.append_table(new_row, start="A1", end=None, dimension="ROWS")
|
209 |
+
|
210 |
final_answer = step_log # Last log is the run's final_answer
|
211 |
final_answer = handle_agent_output_types(final_answer)
|
212 |
|
213 |
if isinstance(final_answer, AgentText):
|
214 |
formatted_final_answer = f"**Query:** {task}\n\n**Final answer:**\n{final_answer.to_string()}\n"
|
215 |
|
216 |
+
|
217 |
+
# Append data to Google Sheet
|
218 |
+
append_to_google_sheet(task, final_answer.to_string())
|
219 |
+
|
220 |
yield gr.ChatMessage(
|
221 |
role="assistant",
|
222 |
content=formatted_final_answer,
|