You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The _run method in SpectrumPlotter now contains complex logic for parsing various input types but lacks a proper Google style docstring. Adding a detailed docstring with descriptions for all parameters and return values would improve clarity.
self,
input_data: Union[str, Dict[str, Any]] =None,
usi: Optional[str] =None,
run_manager: Optional[CallbackManagerForToolRun] =None,
) ->Dict[str, Any]:
session_dir=create_user_session(self.session_id, user_session_dir=True)
db_manager=tools_database()
os.makedirs(session_dir, exist_ok=True)
# If input_data is provided, it should be used instead of the other parametersifinput_data:
# If input_data is a stringifisinstance(input_data, str):
# Check if it's a CSV file pathifinput_data.endswith(".csv"):
df=pd.read_csv(input_data)
# Check required columnsifnot {'usi'}.issubset(df.columns):
return {"error": "CSV file must contain 'usi' column."}
first_row=df.iloc[0]
usi=first_row['usi']
else:
# Attempt to parse the string as JSONtry:
parsed=json.loads(input_data)
exceptExceptionase:
return {"error": f"Invalid input_data format: {e}"}
# If the parsed object contains '__arg1'ifisinstance(parsed, dict) and'__arg1'inparsed:
inner_val=parsed['__arg1']
# If the inner value is a string, try to parse it as JSONifisinstance(inner_val, str):
try:
inner_json=json.loads(inner_val)
exceptExceptionase:
return {"error": f"Invalid nested JSON in '__arg1': {e}"}
elifisinstance(inner_val, dict):
inner_json=inner_valelse:
return {"error": "Unexpected type for '__arg1' value."}
if'usi'ininner_json:
usi=inner_json['usi']
else:
return {"error": "Missing 'usi' key in nested JSON."}
# Otherwise, if the parsed JSON directly has 'usi'elif'usi'inparsed:
usi=parsed['usi']
else:
return {"error": "Invalid JSON structure. Must contain 'usi'."}
# If input_data is already a dictionaryelifisinstance(input_data, dict):
if'usi'ininput_data:
usi=input_data['usi']
elif'__arg1'ininput_data:
inner_val=input_data['__arg1']
ifisinstance(inner_val, str):
try:
inner_json=json.loads(inner_val)
exceptExceptionase:
return {"error": f"Invalid nested JSON in '__arg1': {e}"}
elifisinstance(inner_val, dict):
inner_json=inner_valelse:
return {"error": "Unexpected type for '__arg1' value."}
if'usi'ininner_json:
usi=inner_json['usi']
else:
return {"error": "Missing 'usi' key in nested JSON."}
else:
return {"error": "Invalid input. Provide a dictionary with 'usi' or '__arg1'."}
else:
return {
"error": "Invalid input type. Provide a dictionary with 'usi' or a valid CSV file path."
}
The new IntRange class is useful but does not include a Google DocString format. Consider documenting its purpose, arguments, and methods in Google format for better maintainability.
classIntRange:
def__init__(self, start, end):
self.start=startself.end=endself.range=range(start, end+1)
def__contains__(self, item):
returniteminself.rangedef__iter__(self):
# for help displayreturniter([f"[{self.start}, {self.end}]"])
def__str__(self):
returnf"[{self.start}, {self.end}]"def__repr__(self):
returnself.__str__()
The new add_videos_to_content function improves UI functionality. To be consistent with documentation standards, add a Google docstring detailing its purpose, parameters (if any), and return value.
defadd_videos_to_content():
st.markdown("---")
st.subheader("Illustrative videos")
st.markdown("Here are some illustrative videos to help you understand how to use MetaboT.")
st.video("https://youtu.be/R6OiFt9ryxY")
st.markdown("---")
st.video("https://youtu.be/LpywYlHBWpw")
def __iter__(self):
- # for help display- return iter([f"[{self.start}, {self.end}]"])+ return iter(self.range)
Apply this suggestion
Suggestion importance[1-10]: 8
__
Why: The improved code returns the actual range of integers instead of a string representation, which is a functional improvement for use cases like argparse that expect integer choices.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Description
Updated SpectrumPlotter input parsing and error handling.
Improved database retrieval to check previous interactions.
Refactored Streamlit interface using dialogs and added video content.
Updated deployment scripts, configuration files, and license info.
Changes walkthrough 📝
1 files
Remove outdated commented API key setup code.6 files
Revamp input_data processing and nested JSON error handling.Clean up imports and streamline env variable loading.Enhance data retrieval to check previous interaction when data isnull.Introduce IntRange class for argument range validation.Add initialize_db method for database connection management.Replace modal usage with st.dialog and add illustrative videos.2 files
Adjust question list formatting with minor punctuation fix.Update environment activation command and change license to Apache2.0.3 files
Add setup script for Streamlit config and Heroku deployment.Specify Python version 3.11 for the project.Add Procfile to run the Streamlit app on Heroku.