Spaces:
Sleeping
Sleeping
import langchain | |
import streamlit as st | |
# Create a LangChain client | |
client = langchain.Client() | |
# Define the function that will generate code for a given prompt | |
def generate_code(prompt): | |
"""Generates code for a given prompt. | |
Args: | |
prompt: The prompt to generate code for. | |
Returns: | |
The generated code. | |
""" | |
# Create a request object | |
request = langchain.GenerateCodeRequest( | |
prompt=prompt, | |
language="python", | |
num_tokens=100) | |
# Send the request to the LangChain API | |
response = client.generate_code(request) | |
# Return the generated code | |
return response.code | |
# Create a Streamlit app | |
st.title("LangChain Code Specialist") | |
# Create a text input field for the user to enter a prompt | |
prompt = st.text_input("Enter a prompt:") | |
# Create a button for the user to click to generate code | |
if st.button("Generate Code"): | |
# Generate code for the given prompt | |
code = generate_code(prompt) | |
# Display the generated code | |
st.code(code) |