Vorxart's picture
Update app.py
f3ce3fc verified
raw
history blame
1.74 kB
import streamlit as st
from PIL import Image
import datetime
import time
from ibm_watsonx_ai import APIClient
from ibm_watsonx_ai import Credentials
import os
from ibm_watsonx_ai.foundation_models.utils.enums import ModelTypes
from ibm_watsonx_ai.foundation_models import ModelInference
from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams
from ibm_watsonx_ai.foundation_models.utils.enums import DecodingMethods
import requests
import json
st.title("August 2024 IBM Hackathon")
st.header("Sinple app to find synonyms")
st.sidebar.header("About")
st.sidebar.text("Developed by Tony Pearson")
project_id = os.environ['AUG24_PROJID']
credentials = Credentials(
url = "https://us-south.ml.cloud.ibm.com",
api_key = os.environ['AUG24_APIKEY']
)
client = APIClient(credentials)
client.set.default_project(project_id)
parameters = {
GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
GenParams.MIN_NEW_TOKENS: 1,
GenParams.MAX_NEW_TOKENS: 50,
GenParams.STOP_SEQUENCES: ["\n"]
}
model_id = ModelTypes.GRANITE_13B_CHAT_V2
model = ModelInference(
model_id=model_id,
params=parameters,
credentials=credentials,
project_id = project_id
)
input_word = st.text_input("Enter your input word", "")
prompt_txt = """Generate a list of words similar to the input word."
Input: wordy
Output: verbose, loquacious, talkative
Input: """
prompt_input = prompt_txt + input_word + "\nOutput:"
st.code(prompt_input)
gen_parms_override = None
# GENERATE
if st.button("Generate list of synonyms"):
generated_text_response = model.generate_text(prompt=prompt_input, params=parameters)
st.write("Output from generate_text() method:")
st.success(generated_text_response)