import gradio as gr from huggingface_hub import InferenceClient """ For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co./docs/huggingface_hub/v0.22.2/en/guides/inference """ client = InferenceClient("QuantFactory/llama-3-sqlcoder-8b-GGUF") def respond( message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p, ): messages = [{"role": "system", "content": system_message}] for val in history: if val[0]: messages.append({"role": "user", "content": val[0]}) if val[1]: messages.append({"role": "assistant", "content": val[1]}) messages.append({"role": "user", "content": message}) response = "" for message in client.chat_completion( messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p, ): token = message.choices[0].delta.content response += token yield response prompt = """<|begin_of_text|><|start_header_id|>user<|end_header_id|> Generate a SQL query to answer this question: `{user_question}` You are a data analyst and interpreter. You will be given information about a specific dataset, including its columns and their meanings: year_month: This column is in year-month format, example 2020-12-01 paycell_active_customer: This column represents the number of active customers of Paycell dcb_active_customer: Represents active customers in mobile payment (dcb) paycell_card_active_customer: Represents the number of active users using Paycell card app_active_customer: Represents the number of active customers on our app dcb_total_volume: Column representing the total volume of mobile payment (dcb) at the mentioned time total_card_activation_number: Represents the total activation status of our Paycell card physical_card_activation_number: This column represents the activation number of active physical cards in Paycell virtual_card_activation_number: This column represents the activation number of virtual cards paycell_app_financial_transaction_number: Represents the number of financial transactions made by users using our Paycell app based on their transactions on the relevant date active_customer_distribution_only_dcb: Represents the number of mobile payment (dcb) on the relevant date in the active customer distribution active_customer_distribution_only_pcard: Represents the number of Paycell card in the active customer distribution on the relevant date active_customer_distribution_only_app: Represents the number of app users in the active customer distribution on the relevant date active_customer_distribution_dcb_and_pcard: Represents the number of users using both mobile payment (dcb) and Paycell card but not using Paycell app on the relevant date in the active customer distribution active_customer_distribution_dcb_and_app: Represents the number of users using both mobile payment (dcb) and Paycell app but not using Paycell card on the relevant date in the active customer distribution active_customer_distribution_pcard_and_app: Represents the number of users using both Paycell card and Paycell app but not using mobile payment (dcb) on the relevant date in the active customer distribution active_customer_distribution_dcb_pcard_and_app: Represents the number of users using Paycell card, Paycell app, and mobile payment (dcb) on the relevant date in the active customer distribution. If you cannot answer the question with the available database schema, return 'I do not know' Using this information, you will set up the most suitable SQL statements to answer questions related to the data. These SQL statements will later be executed, so they should be error-free, compatible with Sqllite syntax, and accurately respond to the questions asked. Do not express an opinion or try to explain. Return only the SQL statement. Remember your sql statement will run on SQLite so syntax should be correct. Your output should be clear and void like this output 'Here is the SQL statement to answer the question:'. Also, do not add any comment to the SQL statement which you will generate. Only return SQL statement. DDL statements: CREATE TABLE "dashboard_ana_sayfa" ( "year_month" TIMESTAMP, "paycell_active_customer" INTEGER, "dcb_active_customer" INTEGER, "paycell_card_active_customer" INTEGER, "app_active_customer" INTEGER, "dcb_total_volume" REAL, "total_card_activation_count" INTEGER, "physical_card_activation_count" INTEGER, "virtual_card_activation_count" INTEGER, "paycell_app_financial_transaction_count" INTEGER, "active_customer_distribution_only_dcb" INTEGER, "active_customer_distribution_only_pcard" INTEGER, "active_customer_distribution_only_app" INTEGER, "active_customer_distribution_dcb_and_pcard" INTEGER, "active_customer_distribution_dcb_and_app" INTEGER, "active_customer_distribution_pcard_and_app" INTEGER, "active_customer_distribution_dcb_pcard_and_app" INTEGER )<|eot_id|><|start_header_id|>assistant<|end_header_id|> The following SQL query best answers the question `{user_question}`: ```sql""" """ For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface """ demo = gr.ChatInterface( respond, additional_inputs=[ gr.Textbox(value=prompt, label="System message"), gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"), gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"), gr.Slider( minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)", ), ], ) if __name__ == "__main__": demo.launch()