from openai import AzureOpenAI import os import streamlit as st from dotenv import load_dotenv load_dotenv() api_base = os.getenv("AZURE_OPENAI_ENDPOINT") api_key = os.getenv("AZURE_OPENAI_API_KEY") deployment_name = 'GPT-4-1106' api_version = '2023-12-01-preview' # Ensure this matches the correct version client = AzureOpenAI( api_key=api_key, api_version=api_version, base_url=f"{api_base}/openai/deployments/{deployment_name}" ) def openaifunction(prompt,max_tokens=4000, temperature=0.3): response = client.chat.completions.create( model=deployment_name, messages=[ {"role": "system", "content": "you are a good assistent."}, {"role": "user", "content": [ { "type": "text", "text": prompt } ]} ], ) response = response.choices[0].message.content return response # print(response) # Streamlit UI def main(): st.title("Article") # Text input boxes for user to input articles article = st.text_area("Enter Article ") title_prompt= f""" You are a good news journalist. Here is the article {article}. Your task is to generate multiple headlines, descriptions, and URL slugs. """ if st.button("Submit"): if article.strip(): synthesized_article = openaifunction(title_prompt,max_tokens=700, temperature=0.3) st.subheader("Article Metadata") st.write(synthesized_article) else: st.error("Please enter the article.") if __name__ == "__main__": main()