Spaces:
Sleeping
Sleeping
import streamlit as st | |
# from transformers import pipeline | |
from transformers import pipeline | |
# from PIL import Image | |
# import requests | |
# import torch | |
# from diffusers import DiffusionPipeline | |
from serpapi import GoogleSearch | |
def main(): | |
#Load models | |
text_model_name = "EleutherAI/gpt-neo-1.3B" | |
text_generator = pipeline("text-generation", model=text_model_name, tokenizer=text_model_name) | |
st.title("AI Blog Post Generator") | |
kws = st.checkbox('generate keywords') | |
if kws: | |
title = st.text_input("Enter the title :") | |
generate = st.button('generate') | |
if generate: | |
params = { | |
"q": f'{title}', | |
"location": "Cairo, Egypt", | |
"hl": "en", | |
"gl": "us", | |
"google_domain": "google.com", | |
"api_key": "1d86ba79731e5b3c038fb9f75715883cab027b2f7b41b61ba76d59ec3b9e252d" | |
} | |
search = GoogleSearch(params) | |
results = search.get_dict() | |
results = results['organic_results'] | |
for result in results: | |
title = result['title'] | |
snippet = result['snippet'] | |
st.subheader(title) | |
generated_text = text_generator(snippet,do_sample=True, min_length=150)[0]['generated_text'] | |
st.write(generated_text) | |
# st.write(snippet) | |
else : | |
pass | |
keywords = st.text_input("Enter relevant keywords (comma-separated):") | |
# keywords = [kw.strip() for kw in keywords.split(",")] | |
# st.write(keywords) | |
# generated_text = text_generator(keyword, max_length=150, num_return_sequences=1, temperature=0.7)[0]['generated_text'] | |
# Button to generate blog post | |
# if st.button("Generate Blog"): | |
# if keywords: | |
# # Generate content based on keywords | |
# for keyword in keywords: | |
# generated_text = text_generator(keyword, max_length=150, num_return_sequences=1, temperature=0.7)[0]['generated_text'] | |
# st.subheader(keyword) | |
# st.write(generated_text) | |
# st.header('Conclusion') | |
# generated_text = text_generator(keywords[0], max_length=150, num_return_sequences=1, temperature=0.7)[0]['generated_text'] | |
# st.subheader(keyword) | |
# st.write(generated_text) | |
if __name__ == "__main__": | |
main() | |