File size: 2,520 Bytes
17312e6
2af7dad
 
17312e6
6186ef3
 
957c597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6186ef3
957c597
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6186ef3
957c597
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st
from google import genai
from google.genai import types
from PIL import Image
import json

def main():
    st.title("Analyseur d'Images Géométriques avec Gemini")
    
    # Configuration de l'API key
    api_key = st.sidebar.text_input("Entrez votre clé API Google", type="password")
    if not api_key:
        st.warning("Veuillez entrer votre clé API Google dans la barre latérale")
        return
    
    # Initialisation du client
    try:
        client = genai.Client(
            api_key=api_key,
            http_options={'api_version':'v1alpha'}
        )
    except Exception as e:
        st.error(f"Erreur lors de l'initialisation du client: {e}")
        return
    
    # Upload de l'image
    uploaded_file = st.file_uploader("Choisissez une image géométrique", type=['png', 'jpg', 'jpeg'])
    
    if uploaded_file:
        try:
            # Affichage de l'image
            image = Image.open(uploaded_file)
            st.image(image, caption="Image téléchargée", use_column_width=True)
            
            # Configuration du modèle
            model_name = "gemini-2.0-flash-thinking-exp-01-21"
            
            if st.button("Analyser l'image"):
                with st.spinner("Analyse en cours..."):
                    try:
                        # Génération de la réponse
                        response = client.models.generate_content(
                            model=model_name,
                            config={'thinking_config': {'include_thoughts': True}},
                            contents=[
                                image,
                                "What's the area of the overlapping region?"
                            ]
                        )
                        
                        # Affichage des résultats
                        for part in response.candidates[0].content.parts:
                            if part.thought:
                                st.subheader("Réflexions")
                                st.markdown(part.text)
                            else:
                                st.subheader("Réponse")
                                st.markdown(part.text)
                                
                    except Exception as e:
                        st.error(f"Erreur lors de l'analyse: {e}")
                        
        except Exception as e:
            st.error(f"Erreur lors du traitement de l'image: {e}")

if __name__ == "__main__":
    main()