Untitled

 avatar
unknown
plain_text
2 years ago
2.9 kB
4
Indexable
if 'search_query' in request.form:
            search_query = request.form['search_query'].lower()

            # Load your dataset from a CSV file
            df = pd.read_csv('Medicine_Details.csv')

            # Filter rows based on the search query
            matched_rows = {}
            for index, row in df.iterrows():
                medicine_value = row['Medicine'].lower()
                if search_query in medicine_value:
                    if medicine_value not in matched_rows:
                        matched_rows[medicine_value] = []
                    matched_rows[medicine_value].append(row.to_dict())

            # Translate the "Uses" and "Side Effects" columns for search results
            translated_matched_rows = {}
            for medicine_value, rows in matched_rows.items():
                translated_rows = []
                for row in rows:
                    translated_row = row.copy()
                    if 'Uses' in row:
                        # Translate the "Uses" column to the selected language
                        try:
                            translated_uses = translator.translate(row['Uses'], dest=selected_language).text
                            translated_row['Uses'] = translated_uses
                        except Exception as e:
                            translated_row['Uses'] = "Translation Error"
                    if 'Side_effects' in row:
                        # Translate the "Side Effects" column to the selected language
                        try:
                            translated_side_effects = translator.translate(row['Side_effects'], dest=selected_language).text
                            translated_row['Side_effects'] = translated_side_effects
                        except Exception as e:
                            translated_row['Side_effects'] = "Translation Error"
                    if 'Medicine' in row:
                        # Translate the "Medicine" column to the selected language
                        try:
                            translated_medicine = translator.translate(row['Medicine'], dest=selected_language).text
                            translated_row['Medicine'] = translated_medicine
                        except Exception as e:
                            translated_row['Medicine'] = "Translation Error"
                    translated_rows.append(translated_row)
                translated_matched_rows[medicine_value] = translated_rows

            # Render the template with the search results and selected language
            return render_template('index.html', matched_rows=translated_matched_rows, selected_language=selected_language)

    # If the request method is GET (initial page load), render the template without OCR or search results
    return render_template('index.html')
Editor is loading...