Update app.py
Browse files
app.py
CHANGED
|
@@ -33,40 +33,3 @@ with st.sidebar:
|
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
-
if sidebar_selection == 'json':
|
| 37 |
-
st.title("Projects")
|
| 38 |
-
qa_pairs = []
|
| 39 |
-
if "generated" in st.session_state:
|
| 40 |
-
for i in range(len(st.session_state["generated"])):
|
| 41 |
-
question = st.session_state["past"][i]
|
| 42 |
-
response = st.session_state["generated"][i]
|
| 43 |
-
qa_pairs.append({"question": question, "response": response})
|
| 44 |
-
# Afficher la liste des paires question-réponse au format JSON de manière lisible
|
| 45 |
-
st.text(json.dumps(qa_pairs, indent=4))
|
| 46 |
-
if st.button("Télécharger JSON",type="primary"):
|
| 47 |
-
with open("json.json", "w") as f:
|
| 48 |
-
json.dump(qa_pairs, f, indent=4)
|
| 49 |
-
st.success("Le JSON a été enregistré sous 'json.json'")
|
| 50 |
-
# Créer un bouton pour afficher la section de modification
|
| 51 |
-
if st.button("Modifier" ,type="secondary"):
|
| 52 |
-
st.session_state.modify_mode = True
|
| 53 |
-
if "modify_mode" in st.session_state and st.session_state.modify_mode:
|
| 54 |
-
# Créer un formulaire de modification
|
| 55 |
-
with st.form("Modifier le JSON"):
|
| 56 |
-
# Créer un champ de saisie pour la liste des paires question-réponse
|
| 57 |
-
qa_pairs_json = st.text_area("JSON des paires question-réponse", value=json.dumps(qa_pairs, indent=4))
|
| 58 |
-
|
| 59 |
-
# Créer un bouton de soumission
|
| 60 |
-
submit_button = st.form_submit_button("Enregistrer les modifications")
|
| 61 |
-
|
| 62 |
-
if submit_button:
|
| 63 |
-
# Lire la liste des paires question-réponse saisie par l'utilisateur
|
| 64 |
-
qa_pairs_updated = json.loads(qa_pairs_json)
|
| 65 |
-
|
| 66 |
-
# Enregistrer la liste des paires question-réponse mises à jour
|
| 67 |
-
with open("modified_json.json", "w") as f:
|
| 68 |
-
json.dump(qa_pairs_updated, f, indent=4)
|
| 69 |
-
|
| 70 |
-
st.success("Le JSON modifié a été enregistré sous 'modified_json.json'")
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|