Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,68 @@
|
|
|
|
1 |
import streamlit as st
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
import streamlit as st
|
3 |
+
from PIL import Image
|
4 |
+
import datetime
|
5 |
+
import time
|
6 |
+
from ibm_watsonx_ai import APIClient
|
7 |
+
from ibm_watsonx_ai import Credentials
|
8 |
+
import os
|
9 |
+
from ibm_watsonx_ai.foundation_models.utils.enums import ModelTypes
|
10 |
+
from ibm_watsonx_ai.foundation_models import ModelInference
|
11 |
+
from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams
|
12 |
+
from ibm_watsonx_ai.foundation_models.utils.enums import DecodingMethods
|
13 |
+
import requests
|
14 |
+
import json
|
15 |
+
|
16 |
+
st.title("August 2024 IBM Hackathon")
|
17 |
+
st.header("Sinple app to find synonyms")
|
18 |
+
|
19 |
+
st.sidebar.header("About")
|
20 |
+
st.sidebar.text("Developed by Tony Pearson")
|
21 |
+
|
22 |
+
project_id = os.environ['AUG24_PROJID']
|
23 |
+
|
24 |
+
credentials = Credentials(
|
25 |
+
url = "https://us-south.ml.cloud.ibm.com",
|
26 |
+
api_key = os.environ['AUG24_APIKEY']
|
27 |
+
)
|
28 |
+
|
29 |
+
client = APIClient(credentials)
|
30 |
+
client.set.default_project(project_id)
|
31 |
+
|
32 |
+
parameters = {
|
33 |
+
GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
|
34 |
+
GenParams.MIN_NEW_TOKENS: 1,
|
35 |
+
GenParams.MAX_NEW_TOKENS: 50,
|
36 |
+
GenParams.STOP_SEQUENCES: ["\n"]
|
37 |
+
}
|
38 |
+
|
39 |
+
model_id = ModelTypes.GRANITE_13B_CHAT_V2
|
40 |
+
|
41 |
+
model = ModelInference(
|
42 |
+
model_id=model_id,
|
43 |
+
params=parameters,
|
44 |
+
credentials=credentials,
|
45 |
+
project_id = project_id
|
46 |
+
)
|
47 |
+
|
48 |
+
input_word = st.text_input("Enter your input word", "")
|
49 |
+
|
50 |
+
prompt_txt = """Generate a list of words similar to the input word."
|
51 |
+
|
52 |
+
Input: wordy
|
53 |
+
Output: verbose, loquacious, talkative
|
54 |
+
|
55 |
+
Input: """
|
56 |
+
|
57 |
+
prompt_input = prompt_txt + input_word + "\nOutput:"
|
58 |
+
|
59 |
+
st.code(prompt_input)
|
60 |
+
|
61 |
+
gen_parms_override = None
|
62 |
+
|
63 |
+
# GENERATE
|
64 |
+
|
65 |
+
if st.button("Generate list of synonyms"):
|
66 |
+
generated_text_response = model.generate_text(prompt=prompt_input, params=parameters)
|
67 |
+
st.write("Output from generate_text() method:")
|
68 |
+
st.success(generated_text_response)
|