Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
+
|
| 4 |
+
from dotenv import dotenv_values
|
| 5 |
+
|
| 6 |
+
from langchain.prompts import PromptTemplate
|
| 7 |
+
from langchain.chains import LLMChain
|
| 8 |
+
from langchain.llms import HuggingFaceEndpoint
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
env_vars = dotenv_values(".env")
|
| 12 |
+
LOCAL=False
|
| 13 |
+
HUGGINGFACE_API_TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")
|
| 14 |
+
HUGGINGFACE_MODEL = os.getenv("HUGGINGFACE_MODEL")
|
| 15 |
+
# if not LOCAL:
|
| 16 |
+
# env_vars = {
|
| 17 |
+
# "HUGGINGFACE_API_TOKEN": st.secrets["HUGGINGFACE_API_TOKEN"],
|
| 18 |
+
# "HUGGINGFACE_MODEL": st.secrets["HUGGINGFACE_MODEL"]
|
| 19 |
+
# }
|
| 20 |
+
|
| 21 |
+
# prepare Falcon Huggingface API
|
| 22 |
+
llm = HuggingFaceEndpoint(
|
| 23 |
+
endpoint_url= f"https://api-inference.huggingface.co/models/mrm8488/t5-small-finetuned-quora-for-paraphrasing",
|
| 24 |
+
huggingfacehub_api_token='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',
|
| 25 |
+
task="text-generation",
|
| 26 |
+
model_kwargs = {
|
| 27 |
+
"min_length": 8192,
|
| 28 |
+
"max_length":8192,
|
| 29 |
+
"temperature":0.1,
|
| 30 |
+
"max_new_tokens":4000,
|
| 31 |
+
"num_return_sequences":1
|
| 32 |
+
}
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
topics_template = PromptTemplate(
|
| 37 |
+
input_variables = ['keyword'],
|
| 38 |
+
template = """
|
| 39 |
+
I want you to Write a comprehensive article about "{keyword}" covering the following aspects:
|
| 40 |
+
|
| 41 |
+
Introduction: Provide an engaging introduction to the topic, highlighting its relevance and significance.
|
| 42 |
+
History and Background: Explain the historical context and background of {keyword}.
|
| 43 |
+
Key Concepts and Terminology: Define important terms and concepts related to {keyword}.
|
| 44 |
+
Current State of {keyword}: Discuss the current trends, developments, and challenges in the field of {keyword}.
|
| 45 |
+
Use Cases and Applications: Explore practical applications and use cases of {keyword} in various industries.
|
| 46 |
+
Benefits and Drawbacks: Highlight the advantages and disadvantages of {keyword}.
|
| 47 |
+
Future Outlook: Predict the future trends and potential advancements in {keyword}.
|
| 48 |
+
Conclusion: Summarize the key points and reiterate the importance of {keyword}.
|
| 49 |
+
|
| 50 |
+
Ensure that the article is well-structured, informative, and at least 1500 words long. Use SEO best practices for content optimization.
|
| 51 |
+
""")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
st.title("Blog Writer")
|
| 55 |
+
keyword = st.text_input("Input the keyword you wish to write about")
|
| 56 |
+
|
| 57 |
+
topic_writing_chain = LLMChain(llm= llm, prompt=topics_template, verbose = True)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
with st.spinner('Wait for it...'):
|
| 61 |
+
if keyword:
|
| 62 |
+
topics = topic_writing_chain(keyword)
|
| 63 |
+
st.write(topics)
|
| 64 |
+
st.success('')
|