Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import os | |
| from gradio_client import Client | |
| import time | |
| from PIL import Image | |
| hf_key = os.environ['HF_API_KEY'] | |
| client_url = os.environ['BK_URL'] | |
| client = Client(client_url, hf_token=hf_key) | |
| def get_nl(nl_name, nl_topic, nl_sources, nl_categories, nl_instructions): | |
| gen_stat, html_nl = client.predict( | |
| nl_name=nl_name, nl_topic=nl_topic, nl_sources=nl_sources, nl_categories=nl_categories, nl_instructions=nl_instructions, | |
| api_name="/handle_gradio_nl_req" | |
| ) | |
| return gen_stat, html_nl | |
| with gr.Blocks() as demo: | |
| gr.Image(value = Image.open("NLGen-Logo.png"), interactive = False, width=600, height=150) | |
| #gr.Markdown(value="## NLGen - A fully automated AI based NewsLetter Generator") | |
| gr.Markdown(value="Welcome to NLGen: Tool to generate a Newsletter with categorised articles sourced from the given website links for a given topic.") | |
| gr.Markdown(value="""It takes following inputs: | |
| 1. Name: Name for the Newsletter you want to generate. | |
| 2. Topic: Topic for the Newsletter you want to generate. | |
| 3. Sources: Provide links to websites from where you want to get the articles for the newsletter. | |
| Use Comma separated urls for multiple urls. Provide upto 5 specific urls for the page that contains the article. | |
| For eg. https://analyticsindiamag.com/. | |
| 4. Categories: Categories into which you want your articles to be bucketted into with one liner explaination of each category. Leave it empty if none. | |
| 5. Instructions: Any special instructions you want to give an on categorisation. Leave it empty if none. | |
| After filling the above info press generate button to generate the newsletter. It takes few minutes to collect and filter articles from different sources. | |
| A html formatted Newsletter will be generated and displayed. You can copy and paste generated newsletter in a mail, word doc or on linkedin. | |
| You can find more details on usage at https://github.com/amitagh/nlgen/blob/main/README.md | |
| For any feedback or suggestion please email to amitagh@gmail.com. | |
| """ | |
| ) | |
| nl_name = gr.Textbox( | |
| label="Name:", | |
| value="AI Insights", | |
| ) | |
| nl_topic = gr.Textbox( | |
| label="Topic:", | |
| value="AI Tech news", | |
| ) | |
| nl_sources = gr.Textbox( | |
| label="Sources:", | |
| value="https://techcrunch.com/category/artificial-intelligence/", | |
| ) | |
| nl_categories = gr.Textbox( | |
| label="Categories:", | |
| value="Business, Tech", | |
| ) | |
| nl_instructions = gr.Textbox( | |
| label="Instructions:", | |
| value="Prioritize news related to OpenAI, Apple, Google, Amazon, Microsoft related headlines at the top in each category.", | |
| ) | |
| nl_gen_btn = gr.Button("Generate Newsletter") | |
| nl_gen_status = gr.Textbox( | |
| label="Newsletter Generation Status:", | |
| value="Idle", | |
| interactive=False | |
| ) | |
| nl_html_view = gr.HTML(value="") | |
| nl_gen_btn.click(get_nl, [nl_name, nl_topic, nl_sources, nl_categories, nl_instructions], [nl_gen_status, nl_html_view]) | |
| #Button click action to clear conversation | |
| #btn2.click(clear_conv,inputs=chatbot, outputs=[chatbot, count_msg_view]) | |
| demo.queue() | |
| demo.launch(debug=True) |