Spaces:
Sleeping
Sleeping
File size: 3,280 Bytes
7fef03f 7c32a2b 7fef03f 7c32a2b 7fef03f 3424ade 7c32a2b 3424ade 7c32a2b 3424ade 5ae84aa 7c32a2b 3424ade 664e5d2 3424ade 664e5d2 3424ade 664e5d2 3424ade 664e5d2 3424ade 664e5d2 3424ade 664e5d2 3424ade 664e5d2 5ae84aa 7fef03f 3424ade 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
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()
|