Spaces:
Sleeping
Sleeping
sekpona kokou commited on
Commit ·
798cbb0
1
Parent(s): 2a65b48
add sql runner tool
Browse files- app.py +60 -3
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,6 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import textblob, json
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def sentiment_analysis(text:str)-> str:
|
| 5 |
"""
|
| 6 |
This function takes a string input and returns the sentiment polarity of the text.
|
|
@@ -20,13 +59,31 @@ def sentiment_analysis(text:str)-> str:
|
|
| 20 |
return json.dumps(result, indent=4)
|
| 21 |
|
| 22 |
|
| 23 |
-
|
| 24 |
-
fn
|
| 25 |
inputs=gr.Textbox(placeholder="Enter the text to analyse"),
|
| 26 |
outputs=gr.Textbox(),
|
| 27 |
title="Sentiment Analysis",
|
| 28 |
-
description="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
|
|
|
|
|
|
|
|
|
|
| 31 |
if __name__ == "__main__":
|
| 32 |
demo.launch(mcp_server=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import textblob, json
|
| 3 |
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
from supabase import create_client, Client
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Meilleure pratique : utiliser les variables d'environnement quand possible
|
| 13 |
+
url: str = os.getenv("NEXT_PUBLIC_SUPABASE_URL")
|
| 14 |
+
key: str = os.getenv("NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY")
|
| 15 |
+
|
| 16 |
+
# Création du client
|
| 17 |
+
supabase: Client = create_client(url, key)
|
| 18 |
+
|
| 19 |
+
print("✅ Connexion à Supabase réussie !")
|
| 20 |
+
|
| 21 |
+
def get_from_db(query:str)->str:
|
| 22 |
+
"""
|
| 23 |
+
This function takes a sql query as input and returns result after excecute it in the database.
|
| 24 |
+
Args:
|
| 25 |
+
query (str): SQL Query.
|
| 26 |
+
Returns:
|
| 27 |
+
str: A JSON string containing the result
|
| 28 |
+
"""
|
| 29 |
+
# === Configuration ===
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
response = supabase.rpc(
|
| 35 |
+
"run_sql",
|
| 36 |
+
{"query": 'SELECT * FROM "surveyData" LIMIT 5'}
|
| 37 |
+
).execute()
|
| 38 |
+
return json.dumps(response.data, indent=2)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
def sentiment_analysis(text:str)-> str:
|
| 44 |
"""
|
| 45 |
This function takes a string input and returns the sentiment polarity of the text.
|
|
|
|
| 59 |
return json.dumps(result, indent=4)
|
| 60 |
|
| 61 |
|
| 62 |
+
sentiment_interface = gr.Interface(
|
| 63 |
+
fn=sentiment_analysis,
|
| 64 |
inputs=gr.Textbox(placeholder="Enter the text to analyse"),
|
| 65 |
outputs=gr.Textbox(),
|
| 66 |
title="Sentiment Analysis",
|
| 67 |
+
description="Analyse le sentiment d'un texte (positive / negative / neutral)."
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
sql_excec_interface = gr.Interface(
|
| 71 |
+
fn=get_from_db,
|
| 72 |
+
inputs=gr.Textbox(placeholder="Enter Sql Query"),
|
| 73 |
+
outputs=gr.Textbox(),
|
| 74 |
+
title="Sql Runner in DB",
|
| 75 |
+
description="Return the result from DB."
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
# ==================== Combinaison en onglets (TabbedInterface) ====================
|
| 79 |
+
demo = gr.TabbedInterface(
|
| 80 |
+
[sentiment_interface, sql_excec_interface],
|
| 81 |
+
["Sentiment Analysis", "SQL RUNNER"],
|
| 82 |
+
title="MCP Agent - Multi Tools"
|
| 83 |
)
|
| 84 |
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
if __name__ == "__main__":
|
| 89 |
demo.launch(mcp_server=True)
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
gradio
|
| 2 |
huggingface-hub
|
| 3 |
textblob
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
huggingface-hub
|
| 3 |
textblob
|
| 4 |
+
supabase
|