Py.Cafe

alistairwalsh/

langchain-chatgpt-mysql-query-app

LangChain and ChatGPT Integrated with MySQL Query Interface

DocsPricing
  • app.py
  • requirements.txt
app.py
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
import streamlit as st
import pandas as pd
import requests

# Function to fetch data from REST API
def fetch_data(query):
    # Example REST API URL, adjust as necessary
    api_url = "https://your-api-endpoint.com/query"
    response = requests.post(api_url, json={"query": query})
    if response.status_code == 200:
        data = response.json()
        df = pd.DataFrame(data)
        return df
    else:
        st.error("Failed to fetch data from the API.")
        return pd.DataFrame()

# Streamlit app interface
st.title('LangChain + ChatGPT + MySQL Query App')

query = st.text_input('Enter your query:')
if st.button('Run Query'):
    if query:
        data = fetch_data(query)
        st.write(data)
    else:
        st.error('Please enter a query')