Spaces:
Sleeping
Sleeping
import gradio as gr | |
import os | |
import google.generativeai as palm | |
palm.configure(api_key=os.environ.get('API_KEY')) | |
BOOK_SUMMARY = """Summarize the book {place_holder} in a clear and concise way. | |
The summary should be no more than 1,000 words. | |
The summary should be written in a formal style. | |
The summary should include the following information: | |
The main plot points of the book. | |
The characters in the book and their roles. | |
The themes of the book. | |
The author's message. | |
Examples of desired output format: | |
"The book {place_holder} is about a young woman who goes on a journey to find herself. Along the way, she meets a variety of characters who help her to learn and grow. The book explores the themes of self-discovery, friendship, and love." | |
"{place_holder} is a classic novel that tells the story of a family's struggle to survive during the Great Depression. The book is full of memorable characters and powerful imagery. It is a must-read for anyone interested in American history." | |
Leading words and phrases: | |
The book {place_holder} is about... | |
The main plot points of the book are... | |
The characters in the book include... | |
The themes of the book are... | |
The author's message is... | |
Avoid vague or imprecise language: | |
Do not use words like "good" or "bad" to describe the book. Instead, be specific about what you liked or disliked about the book. | |
Do not use phrases like "it was a great book" or "it was a terrible book." Instead, explain why you thought the book was great or terrible. | |
Provide guidance on what should be done instead: | |
Instead of saying "do not include spoilers," say "please summarize the book without giving away any spoilers." | |
Instead of saying "do not use your own opinions," say "please provide a neutral summary of the book. | |
""" "" | |
def get_book_summary(bookname): | |
response = palm.chat(messages=[BOOK_SUMMARY.format(place_holder=bookname)]) | |
return response.last | |
interface = gr.Interface(fn=get_book_summary, inputs="text", outputs="text") | |
interface.launch() |