Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
import requests
|
| 4 |
+
# Sidebar for options
|
| 5 |
+
st.sidebar.title("Settings")
|
| 6 |
+
# model_options = ["GPT-3.5-turbo", "GPT-4o"]
|
| 7 |
+
# selected_model = st.sidebar.selectbox("Choose the AI model:", model_options)
|
| 8 |
+
language_options = ["Français","English"]
|
| 9 |
+
selected_language = st.sidebar.radio("Choose the language:", language_options)
|
| 10 |
+
if 'mots_cles_associes' not in st.session_state:
|
| 11 |
+
st.session_state.mots_cles_associes = ""
|
| 12 |
+
# Main container
|
| 13 |
+
st.title('Générateur d’articles SEO' if selected_language == "Français" else 'SEO Article Generator')
|
| 14 |
+
|
| 15 |
+
if selected_language == "Français":
|
| 16 |
+
st.subheader('Entrez les détails de votre article:')
|
| 17 |
+
titre_article = st.text_input('Sujet:')
|
| 18 |
+
mot_cle_principal = st.text_input('Mot-clé principal:')
|
| 19 |
+
ton_cible = st.text_input('Ton ciblé:')
|
| 20 |
+
optionnel_data = st.text_input('Ajoutez des données (optionnel):')
|
| 21 |
+
else:
|
| 22 |
+
st.subheader('Enter the details of your article:')
|
| 23 |
+
titre_article = st.text_input('Article Title:')
|
| 24 |
+
mot_cle_principal = st.text_input('Main Keyword:')
|
| 25 |
+
ton_cible = st.text_input('Target Tone:')
|
| 26 |
+
optionnel_data = st.text_input('Add content (optional):')
|
| 27 |
+
# Display the text field with the value from session state
|
| 28 |
+
# mots_cles_associes = st.text_input('Mots-clés associés (séparés par des virgules):', value=st.session_state.mots_cles_associes)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
if st.button('Générer l’article' if selected_language == "Français" else 'Generated Article'):
|
| 32 |
+
if titre_article and mot_cle_principal and ton_cible :
|
| 33 |
+
if selected_language =="Français":
|
| 34 |
+
url = "https://nechba-seo-article-generate.hf.space/generate_article_fr"
|
| 35 |
+
headers = {
|
| 36 |
+
"titre_article": titre_article,
|
| 37 |
+
"mot_cle_principal": mot_cle_principal,
|
| 38 |
+
"ton_cible": ton_cible,
|
| 39 |
+
"optionnel_data": optionnel_data
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
else:
|
| 43 |
+
url = "https://nechba-seo-article-generate.hf.space/generate_article_eng"
|
| 44 |
+
headers = {
|
| 45 |
+
"article_title": titre_article,
|
| 46 |
+
"main_keyword": mot_cle_principal,
|
| 47 |
+
"target_tone": ton_cible,
|
| 48 |
+
"optionnel_data": optionnel_data
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
response = requests.post(url, json=headers)
|
| 53 |
+
if response.status_code != 200:
|
| 54 |
+
st.error('Gemini qeuta ...' if selected_language == "Français" else 'Gemini failed to generate article.')
|
| 55 |
+
st.stop()
|
| 56 |
+
else:
|
| 57 |
+
article = response.text
|
| 58 |
+
json_data = json.loads(article)
|
| 59 |
+
article = json_data['article']
|
| 60 |
+
st.subheader('Article généré' if selected_language == "Français" else 'Generated Article')
|
| 61 |
+
#st.markdown(article)
|
| 62 |
+
|
| 63 |
+
st.markdown(article, unsafe_allow_html=True)
|
| 64 |
+
|
| 65 |
+
#st.markdown("Copiez le texte Markdown ci-dessus!" if selected_language == "Français" else "Copy the above Markdown text!", unsafe_allow_html=True)
|
| 66 |
+
else:
|
| 67 |
+
st.error('Veuillez entrer à la fois un sujet et des mots-clés.' if selected_language == "Français" else 'Please enter both a topic and some keywords.')
|