import newspaper from newspaper import* import gradio as gr import openai import pyshine as ps openai.api_key = "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" import validators import ast def predict(image, model, url_or_text, prompt, temperature, max_tokens, text_in_image, x_cor, y_cor, font_size, backgound_RGB, text_RGB, thickness, opacity, line_space): if text_in_image == "use_url": text = url_or_text if validators.url(url_or_text): article = Article(url="%s" % (url_or_text), language='en') article.download() article.parse() text = article.text response = openai.Completion.create( model=model, prompt = text + "\n"+ prompt, temperature=int(temperature), max_tokens=int(max_tokens), top_p=1, frequency_penalty=0.0, presence_penalty=1 ) text_in_image = response.choices[0].text y_gap = 0 for i in text_in_image.split("\n"): image = ps.putBText(image, i, text_offset_x = int(x_cor), text_offset_y = int(y_cor)+y_gap, vspace = 5, hspace = 2, font_scale = int(font_size), background_RGB = ast.literal_eval(backgound_RGB), text_RGB = ast.literal_eval(text_RGB), thickness = int(thickness), alpha = float(opacity)) y_gap+= int(line_space) return image, response.choices[0].text intr = gr.Interface(predict, ["image", gr.Dropdown(["text-curie-001", "text-davinci-003"], value = "text-curie-001", label = "GPT3- Model"), gr.Textbox(value="https://www.datasciencecentral.com/will-chatgpt-make-fraud-easier/", label = "Provide blog url or directly input the text for better results"), gr.Textbox(value="Title for instagram post", label= "Prompt for what you want the model to do"), gr.Number(value=0.7, label = "How random you want the results to be"), gr.Number(value=100, label= "Max number of words in output"), gr.Textbox(value="use_url"), gr.Number(value=20, label = "X co-ordinate"), gr.Number(value=20, label = "Y co-ordiante"), gr.Number(value=1.0, label = "Font size"), gr.Textbox(value="(228, 225, 222, 211)", label = "Box Color (RGB)"), gr.Textbox(value= "(0, 255,1)", label = "Text Color (RGB)"), gr.Number(value=1, label = "text Thickness"), gr.Number(value=0.8, label = "Opacity of Box"), gr.Number(value=50, label = "Line sapcing")], ["image","text"], title = "Auto Insta Post", description = "Image and url to Instagram Post" ) intr.launch(inline = False)