Vorxart commited on
Commit
3313d78
·
verified ·
1 Parent(s): 24c4bc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -51
app.py CHANGED
@@ -1,68 +1,73 @@
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['WATSONX_PROJECT_ID']
23
 
24
- credentials = Credentials(
25
- url = "https://us-south.ml.cloud.ibm.com",
26
- api_key = os.environ['WATSONX_API_KEY']
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)
 
 
1
  import streamlit as st
2
  from PIL import Image
 
 
3
  from ibm_watsonx_ai import APIClient
4
  from ibm_watsonx_ai import Credentials
 
 
5
  from ibm_watsonx_ai.foundation_models import ModelInference
6
+ from ibm_watsonx_ai.foundation_models.utils.enums import ModelTypes, DecodingMethods
7
  from ibm_watsonx_ai.metanames import GenTextParamsMetaNames as GenParams
8
+ import os
 
 
 
 
 
 
 
 
 
 
9
 
10
+ # Setting up the page layout
11
+ st.set_page_config(page_title="AI Product Design & Development", layout="wide")
 
 
12
 
13
+ # Sidebar - User inputs for Product Specifications
14
+ st.sidebar.title("Product Specifications")
15
+ product_name = st.sidebar.text_input("Product Name", "Example Product")
16
+ material = st.sidebar.selectbox("Material", ["Plastic", "Metal", "Wood", "Composite"])
17
+ dimensions = st.sidebar.text_input("Dimensions (L x W x H in cm)", "10 x 5 x 3")
18
+ constraints = st.sidebar.text_area("Design Constraints", "E.g., Must be lightweight, eco-friendly")
19
+ budget = st.sidebar.number_input("Budget ($)", min_value=0, value=1000)
20
 
21
+ st.sidebar.subheader("Project Info")
22
+ st.sidebar.text("AI-Powered Product Design")
 
 
 
 
23
 
24
+ # Main app title and description
25
+ st.title("AI Product Design & Development Tool")
26
+ st.markdown("""
27
+ Welcome to the AI-powered product design and development tool. This app leverages generative AI to accelerate the design process, optimize products for manufacturing, and simulate product performance.
28
+ """)
29
 
30
+ # Tabs for different sections of the app
31
+ tabs = st.tabs(["Design Generation", "Simulation", "Optimization"])
 
 
 
 
 
 
 
 
32
 
33
+ # IBM WatsonX API Setup
34
+ project_id = os.getenv('WATSONX_PROJECT_ID')
35
+ api_key = os.getenv('WATSONX_API_KEY')
36
 
37
+ if api_key and project_id:
38
+ credentials = Credentials(url="https://us-south.ml.cloud.ibm.com", api_key=api_key)
39
+ client = APIClient(credentials)
40
+ client.set.default_project(project_id)
41
 
42
+ parameters = {
43
+ GenParams.DECODING_METHOD: DecodingMethods.GREEDY,
44
+ GenParams.MIN_NEW_TOKENS: 50,
45
+ GenParams.MAX_NEW_TOKENS: 200,
46
+ GenParams.STOP_SEQUENCES: ["\n"]
47
+ }
48
 
49
+ model_id = ModelTypes.GRANITE_13B_CHAT_V2
50
+ model = ModelInference(model_id=model_id, params=parameters, credentials=credentials, project_id=project_id)
51
 
52
+ # Design Generation Tab
53
+ with tabs[0]:
54
+ st.header("Generate Product Designs")
55
+ st.write("Input your product specifications in the sidebar and click below to generate design concepts.")
56
+
57
+ if st.button("Generate Design Concepts"):
58
+ prompt = f"""You are an AI specialized in product design. Generate creative product design concepts based on the following details:\n
59
+ Product Name: {product_name}\n
60
+ Material: {material}\n
61
+ Dimensions: {dimensions}\n
62
+ Constraints: {constraints}\n
63
+ Budget: {budget} USD\n
64
+ Provide detailed design concepts and explain their features."""
65
+
66
+ try:
67
+ response = model.generate_text(prompt=prompt, params=parameters)
68
+ st.success("Generated Design Concepts:")
69
+ st.write(response)
70
+ except Exception as e:
71
+ st.error(f"An error occurred: {e}")
72
 
73
+ # Simulation and Optimization tabs will be expanded in future steps.