File size: 895 Bytes
ac40033
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import mysql.connector
from mysql.connector import Error


config = {
    "host": "annotation-db.apps.teh2.abrhapaas.com",
    "user": "navid",
    "password": "ZUJSK!1V!PF4ZEnIaylX",
    "charset": "utf8mb4",
    "port": 32107,
    "use_unicode": True
}


import gradio as gr

def greet(name):
    try:
        conn = mysql.connector.connect(**config)
        if conn.is_connected():
            cursor = conn.cursor()
            cursor.execute("SELECT VERSION()")
            version = cursor.fetchone()
            return f"🟢 MySQL Server Version: {version[0]}"

    except Error as e:
        return f"❌ error: {e}"

    finally:
        if 'cursor' in locals():
            cursor.close()
        if 'conn' in locals() and conn.is_connected():
            conn.close()
            print("⛔️Closed.")
    

demo = gr.Interface(fn=greet, inputs="text", outputs="text")
demo.launch()