I would love to. Thank you for reaching out.
The code below produces this error message:
"File "C:\Users\rober\ings\clean_recipe_text.py", line 14, in clean_recipe_text
with open("temp/fraction_free_recipe.txt", "r", encoding='utf-8') as decimal_recipe:
FileNotFoundError: [Errno 2] No such file or directory: 'temp/fraction_free_recipe.txt'
PS C:\Users\rober\ings> "
Fraction_free_recipe is the next to last text file produced by this series of functions.
The first function works fine. It produces the text file “recipe_contents.txt,” but the chain-of-events ends there.
The second function depends on_recipe_contents.txt to produce vulgar_free_recipe.txt (with vulgar meaning unicode).
The third function depends on vulgar_free to produce fraction_free_recipe.txt. The fourth functions depends on fraction_free, meaning all fractions and preceding integers - if they exist - are now converted into decimals.
There just are not any videos or examples in the docs with comparable requirements. And I have reviewed as many as possible, dozens at this point. I would appreciate some instruction on how to proceed. I should note I imported the Python code for convert_unicode_fractions(), convert_regular_fractions() and clean_recipe_text() from modules I wrote that work fine in other contexts. Any constructive feedback would be greatly appreciated.
Thank you.
app = dash.Dash(__name__)
app.layout = html.Div([
dcc.Textarea(
id='textarea-state-example',
value='',
style={'width': '100%', 'height': 200},
placeholder='Please note: Information inside brackets or parantheses will be deleted.'
),
html.Button('Submit', id='textarea-state-example-button', n_clicks=0),
html.Div(id='textarea-state-example-output',
style={'whiteSpace': 'pre-line'})
])
@app.callback(
Output('textarea-state-example-output', 'children'),
Input('textarea-state-example-button', 'n_clicks'),
State('textarea-state-example', 'value')
)
def update_recipe(n_clicks, value):
if n_clicks > 0:
with open("temp/recipe_contents.txt", "w", encoding='utf-8') as recipe_contents:
recipe = value.split('\n')
for line in recipe:
print(line)
recipe_contents.write(line)
recipe_contents.write('\n')
return "Recipe contents written to file."
@app.callback(
Output('textarea-state-example-output', value='vulgar_free_recipe.txt'),
Input('textarea-state-example-output', 'children'),
)
def convert_unicode_fractions():
if os.path.exists('temp/recipe_contents.txt'):
print("Recipe_contents.txt exists.")
print("Now converting unicode fractions to decimals.")
unicode_fractions = convert_unicode_fractions()
print("Output: Convert Unicode Fractions")
print(unicode_fractions())
print(" ")
return "Recipe cleared of unicode fractions."
@app.callback(
Output('textarea-state-example-output', value='fraction_free_recipe.txt'),
Input('textarea-state-example-output', value='vulgar_free_recipe.txt'),
)
def convert_regular_fractions():
if os.path.exists('temp/vulgar_free_recipe.txt'):
print("Vulgar_free_recipe.txt exists")
common_fractions = convert_regular_fractions()
print("Output: Convert Unicode Fractions")
print(common_fractions())
print(" ")
return "Recipe cleared of regular fractions."
@app.callback(
Output('textarea-state-example-output', value='prepared_recipe.txt'),
Input('textarea-state-example-output', value='fraction_free_recipe.txt'),
)
def clean_recipe_textacy():
if os.path.exists('temp/fraction_free_recipe.txt'):
print("Fraction_free_recipe.txt exists")
clean_text = clean_recipe_text()
print("Output: Clean Recipe Text")
print(clean_text())
print(" ")
print("Recipe text cleaned by textacy.")
return "Text prepared for NLP tagging."
if __name__ == '__main__':
app.run_server(debug=True)