File size: 2,336 Bytes
7ce1898
 
 
798cbb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38b75f1
798cbb0
 
 
 
 
 
7ce1898
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
798cbb0
 
7ce1898
 
 
798cbb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7ce1898
 
798cbb0
 
 
7ce1898
b49cb21
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import gradio as gr
import textblob, json


import os
from supabase import create_client, Client
from dotenv import load_dotenv

load_dotenv()


 # Meilleure pratique : utiliser les variables d'environnement quand possible
url: str = os.getenv("NEXT_PUBLIC_SUPABASE_URL") 
key: str = os.getenv("NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY") 

# Création du client
supabase: Client = create_client(url, key)

print("✅ Connexion à Supabase réussie !")

def get_from_db(query:str)->str:
    """
    This function takes a sql query as input and returns result after excecute it in the database.
    Args: 
        query (str): SQL Query.
    Returns:
        str: A JSON string containing the result
    """
    # === Configuration ===
    

   

    response = supabase.rpc(
        "run_sql",
            {"query": query}
    ).execute()
    return json.dumps(response.data, indent=2)




def sentiment_analysis(text:str)-> str:
    """
    This function takes a string input and returns the sentiment polarity of the text.
    Args: 
        text (str): The input text for which the sentiment analysis is to be performed.
    Returns:
        str: A JSON string containing polarity, subjectivity, and assessment 
    """

    out = textblob.TextBlob(text)
    result = out.sentiment
    result =  {
        "polarity": result.polarity,
        "subjectivity": result.subjectivity,
        "assessment": "positive" if result.polarity > 0 else "negative" if result.polarity < 0 else "neutral"
    }
    return json.dumps(result, indent=4)


sentiment_interface = gr.Interface(
    fn=sentiment_analysis,
    inputs=gr.Textbox(placeholder="Enter the text to analyse"),
    outputs=gr.Textbox(),
    title="Sentiment Analysis",
    description="Analyse le sentiment d'un texte (positive / negative / neutral)."
)

sql_excec_interface = gr.Interface(
    fn=get_from_db,
    inputs=gr.Textbox(placeholder="Enter Sql Query"),
    outputs=gr.Textbox(),
    title="Sql Runner in DB",
    description="Return the result from DB."
)

# ==================== Combinaison en onglets (TabbedInterface) ====================
demo = gr.TabbedInterface(
    [sentiment_interface, sql_excec_interface],
    ["Sentiment Analysis", "SQL RUNNER"],
    title="MCP Agent - Multi Tools"
)




if __name__ == "__main__":
    demo.launch(mcp_server=True, share=True)