Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from openai import AzureOpenAI
|
| 2 |
+
import os
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
api_base = os.getenv("AZURE_OPENAI_ENDPOINT")
|
| 10 |
+
api_key = os.getenv("AZURE_OPENAI_API_KEY")
|
| 11 |
+
deployment_name = 'GPT-4-1106'
|
| 12 |
+
api_version = '2023-12-01-preview' # Ensure this matches the correct version
|
| 13 |
+
|
| 14 |
+
client = AzureOpenAI(
|
| 15 |
+
api_key=api_key,
|
| 16 |
+
api_version=api_version,
|
| 17 |
+
base_url=f"{api_base}/openai/deployments/{deployment_name}"
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def openaifunction(prompt,max_tokens=4000, temperature=0.3):
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model=deployment_name,
|
| 23 |
+
messages=[
|
| 24 |
+
{"role": "system", "content": "you are a good assistent."},
|
| 25 |
+
{"role": "user", "content": [
|
| 26 |
+
{
|
| 27 |
+
"type": "text",
|
| 28 |
+
"text": prompt
|
| 29 |
+
}
|
| 30 |
+
]}
|
| 31 |
+
],
|
| 32 |
+
|
| 33 |
+
)
|
| 34 |
+
response = response.choices[0].message.content
|
| 35 |
+
return response
|
| 36 |
+
# print(response)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# Streamlit UI
|
| 43 |
+
def main():
|
| 44 |
+
st.title("Article")
|
| 45 |
+
|
| 46 |
+
# Text input boxes for user to input articles
|
| 47 |
+
article = st.text_area("Enter Article ")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
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.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
if st.button("Submit"):
|
| 58 |
+
if article.strip():
|
| 59 |
+
synthesized_article = openaifunction(title_prompt,max_tokens=700, temperature=0.3)
|
| 60 |
+
st.subheader("Article Metadata")
|
| 61 |
+
st.write(synthesized_article)
|
| 62 |
+
else:
|
| 63 |
+
st.error("Please enter the article.")
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
main()
|