File size: 1,675 Bytes
7fef03f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()