Spaces:
Sleeping
feat: Allow result to be downloaded as Excel file
Browse files-Updated gradio version in requirements.txt from 4.31.5 to 5.12.0 to fix
compatibilty issue with python 3.13. audioop-lts module was added to
gradio in 5.4.0 to compensate for removal of audioop module in Python
3.13+. See https://github.com/gradio-app/gradio/pull/9757.
-Added newlines to ends of .txt files and app.py
-Modified Gradio interface in app.py to give an additional file as
output. File is created by converting the original output DataFrame
using df.to_excel.
-Added dotenv package for easier local testing with .env file.
-Added .gitignore to ignore venv folder and .env file when pushing to
origin.
-Amend: added dotenv 1.0.1 to requirements.txt.
-Amend 2: Non-urgent issue requiring fix: output.xlsx is created in
local directory when testing locally. Will be good to cleanup when local
testing server is shut down.
-Amend 3: Added output.xlsx to .gitignore.
- .gitignore +3 -0
- app.py +12 -2
- prompt.txt +1 -1
- requirements.txt +3 -2
- user_instructions.txt +1 -1
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
.env
|
| 3 |
+
output.xlsx
|
|
@@ -5,6 +5,10 @@ import pandas as pd # For easier data handling
|
|
| 5 |
from openai import OpenAI # For sending the quotes to OpenAI for tagging
|
| 6 |
import openpyxl # Requirement for reading Excel files into pandas Dataframes
|
| 7 |
import json # For conversion of OpenAI responses into json/dictionary objects so the contents can be extracted
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Import prompt for requesting the tags from OpenAI
|
| 10 |
with open("prompt.txt", "r") as prompt_file:
|
|
@@ -97,7 +101,10 @@ def process_quotes(quotes_file_path: str, quotes_col_name: str, tags_string: str
|
|
| 97 |
quotes_df['Tags'] = quotes_data.apply(tag_quote, args=(tags_list,))
|
| 98 |
|
| 99 |
# Return only the quotes column and the new tags column
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
# Define user interface structure
|
| 103 |
demo = gr.Interface(
|
|
@@ -107,7 +114,10 @@ demo = gr.Interface(
|
|
| 107 |
gr.Textbox(label="Name of quotes column"),
|
| 108 |
gr.Textbox(label = "List of tags separated by commas")
|
| 109 |
],
|
| 110 |
-
outputs=
|
|
|
|
|
|
|
|
|
|
| 111 |
title="Automated Research Code Tagger",
|
| 112 |
description=INSTRUCTIONS
|
| 113 |
)
|
|
|
|
| 5 |
from openai import OpenAI # For sending the quotes to OpenAI for tagging
|
| 6 |
import openpyxl # Requirement for reading Excel files into pandas Dataframes
|
| 7 |
import json # For conversion of OpenAI responses into json/dictionary objects so the contents can be extracted
|
| 8 |
+
from dotenv import load_dotenv # For loading environment variables in local environment
|
| 9 |
+
|
| 10 |
+
# Load environment variables from local .env file if it exists; otherwise this does nothing
|
| 11 |
+
load_dotenv()
|
| 12 |
|
| 13 |
# Import prompt for requesting the tags from OpenAI
|
| 14 |
with open("prompt.txt", "r") as prompt_file:
|
|
|
|
| 101 |
quotes_df['Tags'] = quotes_data.apply(tag_quote, args=(tags_list,))
|
| 102 |
|
| 103 |
# Return only the quotes column and the new tags column
|
| 104 |
+
output_df = quotes_df[[quotes_col_name, 'Tags']]
|
| 105 |
+
output_file_path = "output.xlsx"
|
| 106 |
+
output_df.to_excel(output_file_path, index=False)
|
| 107 |
+
return output_df, output_file_path
|
| 108 |
|
| 109 |
# Define user interface structure
|
| 110 |
demo = gr.Interface(
|
|
|
|
| 114 |
gr.Textbox(label="Name of quotes column"),
|
| 115 |
gr.Textbox(label = "List of tags separated by commas")
|
| 116 |
],
|
| 117 |
+
outputs=[
|
| 118 |
+
gr.Dataframe(headers=["Quote", "Tags"], column_widths=["70%", "30%"], scale=2),
|
| 119 |
+
gr.File(label="Output data in file format")
|
| 120 |
+
],
|
| 121 |
title="Automated Research Code Tagger",
|
| 122 |
description=INSTRUCTIONS
|
| 123 |
)
|
|
@@ -14,4 +14,4 @@ Tag list:
|
|
| 14 |
Respond in the following format:
|
| 15 |
{{
|
| 16 |
"tags":[<tagName1>, <tagName2>]
|
| 17 |
-
}}
|
|
|
|
| 14 |
Respond in the following format:
|
| 15 |
{{
|
| 16 |
"tags":[<tagName1>, <tagName2>]
|
| 17 |
+
}}
|
|
@@ -1,3 +1,4 @@
|
|
| 1 |
-
gradio==
|
| 2 |
openai==1.59.3
|
| 3 |
-
openpyxl==3.1.5
|
|
|
|
|
|
| 1 |
+
gradio==5.12.0
|
| 2 |
openai==1.59.3
|
| 3 |
+
openpyxl==3.1.5
|
| 4 |
+
dotenv==1.0.1
|
|
@@ -12,4 +12,4 @@ You may then copy them into an Excel file for further processing. Please allow 5
|
|
| 12 |
|
| 13 |
Please bear in mind that the tags are AI generated so check your results to ensure they make sense before using them.
|
| 14 |
I will not be responsible for mistakes made by the AI, but I can try to fix them if you alert me.
|
| 15 |
-
-Kenneth
|
|
|
|
| 12 |
|
| 13 |
Please bear in mind that the tags are AI generated so check your results to ensure they make sense before using them.
|
| 14 |
I will not be responsible for mistakes made by the AI, but I can try to fix them if you alert me.
|
| 15 |
+
-Kenneth
|