A colllection of AI/ML Apps made using LLMs, LangChain and Streamlit etc.
# api.py
import requests



API_BASE_URL = "https://tgapi-7d0b0583d985.herokuapp.com/api/v1/coderunner/execute"  # Replace this with the actual API endpoint URL
def execute_gpt_code(code: str) -> str:
    """
    Execute Python code using the GPT model via the API endpoint.
    
    Args:
        code (str): Python code to be executed.
    
    Returns:
        str: Execution result from the API.
    """
    try:
        response = requests.post(API_BASE_URL, json={"code": code})
        response.raise_for_status()  # Raise an exception for 4xx and 5xx status codes
        result = response.json()["result"]
        return result
    except requests.exceptions.RequestException as e:
        return f"Error occurred: {e}"

# Example usage
if __name__ == "__main__":
    python_code = """
    def hello():
        return "Hello, World!"
    print(hello())
    """
    execution_result = execute_gpt_code(python_code)
    print("Execution Result:")
    print(execution_result)

ai-codeexecutor/api/api.py
pyGuru123/LLM-Apps
# app.py
from api.api import execute_gpt_code
import streamlit as st

def main():
    st.title("AI-Powered Code Executor")

    # User input for code execution
    code_input = st.text_area("Enter Python Code Here:")

    if st.button("Execute"):
        # Call the API to execute the code
        execution_result = execute_gpt_code(code_input)
        st.write("Execution Result:")
        st.code(execution_result)

if __name__ == "__main__":
    main()

ai-codeexecutor/app.py
pyGuru123/LLM-Apps