import streamlit as st from datetime import datetime from huggingface_hub import HfApi from src.text_content import REVIEW_TEXT, INTRO_TEXT_AR, INTRO_TEXT_EN, INTRO_TEXT_FR from src.dataframes import INTERVENTIONS_PROCESSED_URL, VERIFIED_REQUESTS_PROCESSED_URL from src.utils import parse_gg_sheet import plotly.express as px def id_review_submission(api: HfApi): """Id review submission form""" # collapse the text with st.expander("🔍 Review of requests | مراجعة طلب مساعدة"): st.markdown(REVIEW_TEXT) id_to_review = st.number_input("Enter id / أدخل الرقم", min_value=0, value=0, step=1) reason_for_review = st.text_area("Explain why / أدخل سبب المراجعة") if st.button("Submit / أرسل"): if reason_for_review == "": st.error("Please enter a reason / الرجاء إدخال سبب") else: filename = f"review_id_{id_to_review}_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.txt" with open(filename, "w") as f: f.write(f"id: {id_to_review}, explanation: {reason_for_review}\n") api.upload_file( path_or_fileobj=filename, path_in_repo=filename, repo_id="nt3awnou/review_requests", repo_type="dataset", ) st.success("Submitted at https://huggingface.co/datasets/nt3awnou/review_requests/ تم الإرسال") def show_embed_code(): with st.expander(_("💻 For Developers only, embed code for the map")): st.code( """ """, language="html", ) def show_dataframes_metrics(len_requests, len_interventions, len_solved_verified_requests, lang, show_col_3=False): if lang == "en": # with st.expander("📝 Nt3awnou Platform Description"): st.markdown(INTRO_TEXT_EN, unsafe_allow_html=True) if show_col_3: col1, col2, col3 = st.columns([1, 1, 1]) else: col1, col2 = st.columns([1, 1]) with col1: st.metric( "# Number of help requests", len_requests, ) with col2: st.metric( "# Number of interventions", len_interventions + len_solved_verified_requests, ) if show_col_3: with col3: st.metric( "# Number of solved requests", len_solved_verified_requests, ) elif lang == "ar": # with st.expander("📝 شرح منصة نتعاونو"): st.markdown(INTRO_TEXT_AR, unsafe_allow_html=True) if show_col_3: col1, col2, col3 = st.columns([1, 1, 1]) else: col1, col2 = st.columns([1, 1]) with col1: st.metric( "# عدد طلبات المساعدة", len_requests, ) with col2: st.metric( "# عدد التدخلات", len_interventions + len_solved_verified_requests, ) if show_col_3: with col3: st.metric( "# عدد الطلبات المستجاب لها", len_solved_verified_requests, ) elif lang == "fr": # with st.expander("📝 Description de la plateforme Nt3awnou"): st.markdown(INTRO_TEXT_FR, unsafe_allow_html=True) if show_col_3: col1, col2, col3 = st.columns([1, 1, 1]) else: col1, col2 = st.columns([1, 1]) with col1: st.metric( "# Nombre de demandes d'aide", len_requests, ) with col2: st.metric( "# Nombre d'interventions", len_interventions + len_solved_verified_requests, ) if show_col_3: with col3: st.metric( "# Nombre de demandes résolues", len_solved_verified_requests, ) @st.cache_data(ttl=60*60*24) def cached_parse_gg_sheet(url): return parse_gg_sheet(url) def show_charts(): st.subheader(_("📊 **Charts**")) col1, col2 = st.columns([1, 1]) # interventions_categories interventions_processed_df = cached_parse_gg_sheet(INTERVENTIONS_PROCESSED_URL) supply_data = interventions_processed_df["supplies_category"].str.split(",").explode().str.strip('[] \'').dropna().astype("category") interv_fig = px.pie(supply_data, names='supplies_category', title=_('Supplies Categories')) with col1: st.plotly_chart(interv_fig) # requests_categories requests_processed_df = cached_parse_gg_sheet(VERIFIED_REQUESTS_PROCESSED_URL) need_data = requests_processed_df["need_category"].str.split(",").explode().str.strip('[] \'').dropna().astype("category") req_fig = px.pie(need_data, names='need_category', title=_('Needs Categories')) with col2: st.plotly_chart(req_fig) def show_donations(lang): st.subheader(_("📝 **Donations**")) if lang == "en": st.markdown( """