ai_article_writer_web_ui/webui.py

38 lines
2.0 KiB
Python
Raw Normal View History

2024-02-17 22:04:06 +03:30
import gradio as gr
2024-02-18 03:56:20 +03:30
from scrape_amazon import AmazonScraper, AIInterface
2024-02-17 22:04:06 +03:30
2024-02-18 03:56:20 +03:30
llms = ['meta-llama/Llama-2-70b-chat-hf', "mistralai/Mixtral-8x7B-Instruct-v0.1", "togethercomputer/LLaMA-2-7B-32K"]
scraper = AmazonScraper()
aii = AIInterface()
2024-02-17 22:04:06 +03:30
2024-02-18 03:56:20 +03:30
def write_article(url, ai_prompt):
2024-02-17 22:04:06 +03:30
# Your logic to fetch HTML content from the URL
# Replace this with your actual implementation
2024-02-18 03:56:20 +03:30
text = scraper.get_product_info_and_reviews(url)
images = list(scraper.images)[0]
prompt_for_ai = "Write a summary of the following product and an overview of people's experiences based on the provided reviews of it as follows. Format it nicely and professionally in HTML:\n\n" + text
# prompt_for_ai = f"Write a summary of the following product and an overview of people's experiences based on the provided reviews of it as follows. Format it nicely and professionally in HTML. The title of this product should links to {url}. Also include this image {images} after the first or second paragraph as a link to {url} and <figcaption>Image from Amazon.com</figcaption>:\n\n" + text
ai_response = aii.ask_ai(prompt_for_ai, model=llms[1])
print(ai_response)
html_content = ai_response
prompt_for_ai = f"Take the following HTML code and slightly modify it by converting the names of this product to links to {url}. Also include this image {images} after the first or second paragraph as a link to {url} and caption it with <figcaption>Image from Amazon.com</figcaption>. Return a nice and professional HTML code:\n" + ai_response
html_content = aii.ask_ai(prompt_for_ai, model=llms[1])
print(html_content)
2024-02-17 22:04:06 +03:30
return html_content
# Define the Gradio interface
iface = gr.Interface(
fn=write_article,
2024-02-18 03:56:20 +03:30
inputs=["text", gr.components.Textbox(lines=10, placeholder="Enter AI prompt here...", label="AI Prompt:")], # Text input for the URL
2024-02-17 22:04:06 +03:30
outputs="html", # Display HTML content
title="URL to HTML Converter",
description="Enter a URL to get its HTML content."
)
# Launch the Gradio app
2024-02-18 03:56:20 +03:30
iface.launch(server_port=7373, share=True)