ArticleMetadata / app.py
Harsh051015's picture
Update app.py
7c32a2b verified
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 assistant."},
{"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 the user to input articles
article = st.text_area("Enter Article ")
title_prompt= f""" You are a good news journalist. Here is the article {article}. \n
Your task is to generate multiple Headlines, Descriptions, and URL slugs.\n
Your response needs to be included within the article.\n
=========================
Instructions:
1. The objective is to provide one-sentence headlines without using a colon to connect two sentences.
2. It's advisable to aim for headlines of 60-80 characters for optimal results. Please ensure that the generated headline aligns with Google's guidelines for headline length.
3. Please verify that the description adheres to Google's guidelines for description length:
Target: Aim for descriptions between 120-160 characters. This range ensures that your description remains informative even if truncated.
Focus: Clearly describe the content's value to the user.
Truncation: Be aware that Google might opt to use content from your webpage instead of your description if it's deemed more relevant.
4. Please generate engaging text for a Twitter post under 280 characters, sharing the link to this article (with a placeholder for the link). This tweet should use emojis to captivate attention and emphasize key points.
=========================
The response must be like-
\n
Headlines:
\n1.
\n2.
....
\n
Descriptions:
\n1.
\n2.
....
\n
URL Slugs:
\n1.
\n2.
....
Twitter Post:
\n 1.
==========================
Restrictions:
1. Don't provide any explanation or details
"""
if st.button("Submit"):
if article.strip():
synthesized_article = openaifunction(title_prompt,max_tokens=800, temperature=0.3)
st.subheader("Article Metadata")
st.write(synthesized_article)
else:
st.error("Please enter the article.")
if __name__ == "__main__":
main()