| import streamlit as st |
| from langchain import OpenAI, PromptTemplate, LLMChain |
| from langchain.text_splitter import CharacterTextSplitter |
| from langchain.chains.mapreduce import MapReduceChain |
| from langchain.prompts import PromptTemplate |
| from langchain.chat_models import AzureChatOpenAI |
| from langchain.chains.summarize import load_summarize_chain |
| from langchain.chains import AnalyzeDocumentChain |
| from PyPDF2 import PdfReader |
| from langchain.document_loaders import TextLoader |
| from langchain.indexes import VectorstoreIndexCreator |
| from langchain.document_loaders import PyPDFLoader |
| import os |
| import openai |
| import requests |
| import time |
| import os |
| import urllib.request |
| from PIL import Image |
| import os |
|
|
|
|
| os.environ["OPENAI_API_TYPE"] = "azure" |
| os.environ["OPENAI_API_VERSION"] = "2023-03-15-preview" |
|
|
| image_api_base = 'https://openaistudio255.openai.azure.com/' |
| image_api_key = os.environ["OPENAI_SECRETKEY"] |
|
|
|
|
| openai.api_type = "azure" |
| openai.api_base = "https://embeddinguseopenai.openai.azure.com/" |
| openai.api_version = "2023-03-15-preview" |
| openai.api_key = os.environ["OPENAI_API_KEY"] |
|
|
|
|
|
|
| |
|
|
|
|
| image = Image.open('Wipro logo.png') |
| st.image(image) |
|
|
| st.title(" ideate sustainabile product designs with AI") |
|
|
|
|
| st.header("What is your idea? Type it here and the AI will co-design your concept") |
|
|
| yourquestion = st.text_input('Your topic', 'modern car design with solar panels on the top') |
| st.write('Your input is ', yourquestion) |
|
|
|
|
|
|
| if st.button("Visuvalize for ideas "): |
| body = { "caption": yourquestion , "resolution": "512x512" } |
|
|
| imageapi_version = '2022-08-03-preview' |
| url = "{}dalle/text-to-image?api-version={}".format(image_api_base, imageapi_version) |
| headers= { "api-key": image_api_key, "Content-Type": "application/json" } |
|
|
| |
| submission = requests.post(url, headers=headers, json=body) |
| operation_location = submission.headers['Operation-Location'] |
| retry_after = submission.headers['Retry-after'] |
| status = "" |
|
|
| while (status != "Succeeded"): |
| time.sleep(int(retry_after)) |
| response = requests.get(operation_location, headers=headers) |
| status = response.json()['status'] |
| image_url = response.json()['result']['contentUrl'] |
| |
| st.image(image_url, width = 512) |
|
|
|
|
| if True==False: |
| if st.button("Ask for ideas "): |
| template = """ |
| You are an AI assistant. |
| {concept} |
| """ |
| |
| yourquestionideas = "List creative ideas of " + yourquestion |
| |
| response = openai.ChatCompletion.create( |
| engine="gpt-35-turbo", |
| messages = [{"role":"system","content":"You are an AI assistant that can come up with creative product ideas."},{"role":"user","content":yourquestionideas}], |
| temperature=0.99, |
| max_tokens=800, |
| top_p=1, |
| frequency_penalty=0, |
| presence_penalty=0, |
| stop=None) |
| |
| |
| st.write(response) |
|
|