Download app.py from FT-BT/FT: direct link, hf CLI and curl.
- Browser
- Download file 3.55 kB
-
https://huggingface.co/spaces/FT-BT/FT/resolve/main/app.py
- Command line
-
hf download hf://spaces/FT-BT/FT/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FT-BT/FT/resolve/main/app.py
3.55 kB
| import gradio as gr | |
| import openai | |
| import os | |
| import re | |
| # Set up OpenAI API key | |
| openai.api_key = os.environ['API_TOKEN'] | |
| def generate_text(prompt, model_engine="text-davinci-003"): | |
| completions = openai.Completion.create( | |
| engine=model_engine, | |
| prompt=prompt, | |
| max_tokens=200, | |
| n=1, | |
| stop=None, | |
| temperature=0.7, | |
| ) | |
| return completions.choices[0].text.strip() | |
| def process_article(article): | |
| # Define the prompts for each output | |
| prompts = [ | |
| "You are a brand ambassador for a brand that has a voice that is 'thoughtful, open-minded, curious, celebrates creativity, innovation, and non-conformity. It has a tone that is inspirational, empowering, and optimistic, and a brand personality that is rebellious, forward-thinking, and non-conformist'. When using the brand's voice, don't actually mention any of those specific words. Do not use hashtags. Do not use emojis.Give me the top 5 thought-provoking questions that could come from this article and that would drive positive engagement on Twitter. Write the questions in the brand's voice. Do not use hashtags. Do not use emojis.", | |
| "Give me the top 3 summaries for the article in short and engaging sentences written in the brand's voice. Do not use colon-structured sentences. Do not use colons. Do not use hashtags. Do not use emojis.", | |
| "Formulate a summary of the article below in the link in multiple tweets. Keep in mind the maximum length of 280 characters per tweet. Use short sentences and do not stretch them across multiple tweets. Start the tweets with a consistent numbering scheme. Do not use hashtags. Do not use emojis.", | |
| "Please pull the sentence from the article below that is the most shocking, bold, dynamic, or interesting. Present the complete sentence with the quote exactly as it is written in the article.", | |
| "Pretend you are a futurist. Ponder the possibilities and breakthroughs from the article below and then predict the most interesting or exciting thing that could happen in the next 20 years. Present your prediction in the form of a question and ask if it is possible. Do not specifically mention 20 years and instead just reference the future when presenting your prediction. Do not use hashtags. Do not use emojis." | |
| ] | |
| outputs = [] | |
| for prompt in prompts: | |
| # Generate output using the GPT-3.5 Turbo model | |
| generated_text = generate_text(prompt + " " + article) | |
| output = re.sub(r'\n', ' ', generated_text).strip() | |
| outputs.append(output) | |
| # Join the outputs with newline characters to create hard returns | |
| outputs = '\n'.join(outputs) | |
| return outputs.split('\n') | |
| # Custom CSS for auto-height Textboxes | |
| css = """ | |
| .output-text { | |
| height: auto !important; | |
| min-height: 60px; | |
| max-height: 200px; | |
| overflow-y: auto !important; | |
| } | |
| """ | |
| iface = gr.Interface( | |
| fn=process_article, | |
| inputs=gr.inputs.Textbox(lines=20, label="Enter article text"), | |
| outputs=[ | |
| gr.outputs.Textbox(label="Top 5 Thought-Provoking Questions"), | |
| gr.outputs.Textbox(label="Top 3 Summaries"), | |
| gr.outputs.Textbox(label="The Story in Tweets"), | |
| gr.outputs.Textbox(label="Most Interesting Moment"), | |
| gr.outputs.Textbox(label="Futurist Prediction Presented as a Question") | |
| ], | |
| title="Article and Video Transcript Content", | |
| description="Enter an article for potential publishing content written in the Freethink Media voice.", | |
| css=css # Add the custom CSS | |
| ) | |
| iface.launch(debug=True, inbrowser=True) | |