File size: 1,744 Bytes
f3ce3fc
6f84299
f3ce3fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

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)