codegen_test / app.py
yashwanthputikam99's picture
Update app.py
1ff7985 verified
import streamlit as st
import getpass
from ibm_watsonx_ai.foundation_models import Model
def get_credentials():
# Simulating the input of API key 'abc123456'
apikey = 'ws_9FlJesGn-OtLTG5MeUx-uhTQvgA3CvhlB354AbXEh'
return {
"url": "https://us-south.ml.cloud.ibm.com",
"apikey": apikey
}
# Parameters and model initialization
model_id = "codellama/codellama-34b-instruct-hf"
parameters = {
"decoding_method": "greedy",
"max_new_tokens": 1000,
"min_new_tokens": 1,
"stop_sequences": ["<end of code>"],
"repetition_penalty": 1
}
# Streamlit app begins
st.title('Code Generation with IBM WATSONX AI')
# Input prompt text area
prompt_input = st.text_area('Enter your prompt (instructions):', height=250)
# Button to generate code
if st.button('Generate Code'):
st.text("Generating code...")
# Initialize the model with credentials
credentials = get_credentials()
model = Model(
model_id=model_id,
params=parameters,
credentials=credentials,
project_id="eb2237d8-f81e-4c03-a952-8510fce2ca46",
)
# Generate response based on the prompt
generated_response = model.generate_text(prompt=prompt_input, guardrails=False)
# Display the generated response
st.subheader('Generated Code:')
st.code(generated_response)
# Instructions or info section
st.markdown('''
### Instructions:
- Enter the instructions for code generation in the text area.
- Click on **Generate Code** to generate Python code based on the instructions.
''')