Update app.py
Browse files30 unmodified lines313233343536373839404142434445464748491 unmodified line5152535455565758596061626364656667686970717273747576777879808182838485861 unmodified line88899091929394959697989910010110210310410510610710827 unmodified lines1361371381391401411421431441451461471481 unmodified line1501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821836 unmodified lines19019119219319419519617 unmodified lines21421521621721821922022111 unmodified lines233234235236237238239240241242243244245165 unmodified lines41141241341441541641794 unmodified lines51251351451551651751830 unmodified lines# Define multiple sets of instruction templatesINSTRUCTION_TEMPLATES = {"material discovery summary": {"intro": """Your task is to take the input text provided and turn it into a lively, engaging conversation between a professor and a student in a panel discussion that describes a new material. The professor acts like Richard Feynman, but you never mention the name.The input text is the result of a design developed by SciAgents, an AI tool for scientific discovery that has come up with a detailed materials design.Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that could be discussed in a podcast.Define all terms used carefully for a broad audience of listeners.""","text_instructions": "First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for a high quality presentation.","scratch_pad": """Brainstorm creative ways to discuss the main topics and key points you identified in the material design summary, especially paying attention to design features developed by SciAgents. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.Keep in mind that your description should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.1 unmodified lineWrite your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.Make sure to make it fun and exciting. You never refer to the podcast, you just discuss the discovery and you focus on the new material design only.""","prelude": """Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.""","dialog": """Write a very long, engaging, informative dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. The presentation must focus on the novel aspects of the material design, behavior, and all related aspects.Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience, but make it detailed, logical, and technical so that it has all necessary aspects for listeners to understand the material and its unexpected properties.Remember, this describes a design developed by SciAgents, and this must be explicitly stated for the listeners.Never use made-up names for the hosts and guests, but make it an engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.Make the dialogue as long and detailed as possible, while still staying on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest podcast episode you can, while still communicating the key information from the input text in an entertaining way.At the end of the dialogue, have the host and guest speakers naturally summarize the main insights and takeaways from their discussion. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas one last time before signing off.The podcast should have around 20000 words."""},"podcast": {"intro": """Your task is to take the input text provided and turn it into an lively, engaging, informative podcast dialogue, in the style of NPR. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages.Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that could be discussed in a podcast.Define all terms used carefully for a broad audience of listeners.""","text_instructions": "First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for a high quality presentation.","scratch_pad": """Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.Keep in mind that your podcast should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.1 unmodified lineWrite your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.Make sure to make it fun and exciting.""","prelude": """Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.""","dialog": """Write a very long, engaging, informative podcast dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience.Never use made-up names for the hosts and guests, but make it an engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.Make the dialogue as long and detailed as possible, while still staying on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest podcast episode you can, while still communicating the key information from the input text in an entertaining way.At the end of the dialogue, have the host and guest speakers naturally summarize the main insights and takeaways from their discussion. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas one last time before signing off.The podcast should have around 20000 words.""",},"lecture": {"intro": """You are Professor Richard Feynman. Your task is to develop a script for a lecture. You never mention your name.27 unmodified linesThere is only one speaker, you, the professor. Stay on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest lecture you can, while still communicating the key information from the input text in an engaging way.At the end of the dialogue, naturally summarize the main insights and takeaways from the lecture. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner.Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas one last time before class is over.The lecture should have around 20000 words.""",},"short summary": {"intro": """Your task is to develop a summary of a paper. You never mention your name.1 unmodified lineDefine all terms used carefully for a broad audience.""","text_instructions": "First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in an accurate summary.","scratch_pad": """Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.Keep in mind that your summary should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.Define all terms used clearly and spend effort to explain the background.Write your brainstorming ideas and a rough outline for the summary here. Be sure to note the key insights and takeaways you want to reiterate at the end.Make sure to make it fun and exciting.""","prelude": """Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.""","dialog": """Write a a script here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to the students.Start your script by stating that this is a summary, referencing the title or headings in the input text.Include clear definitions and terms, and examples.Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.There is only one speaker, you. Stay on topic and maintaining an engaging flow.Naturally summarize the main insights and takeaways from the lecture. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner.The summary should have around 512 words.""",},}6 unmodified linesINSTRUCTION_TEMPLATES[template]["scratch_pad"],INSTRUCTION_TEMPLATES[template]["prelude"],INSTRUCTION_TEMPLATES[template]["dialog"])import concurrent.futures as cfimport glob17 unmodified linesSTANDARD_TEXT_MODELS = ["o1-preview-2024-09-12","gpt-4o-2024-08-06","o1-mini-2024-09-12","gpt-4o-mini","openai/custom_model",]11 unmodified lines"shimmer",]# Uncomment and configure Sentry if needed# sentry_sdk.init(os.getenv("SENTRY_DSN"))# Uncomment and configure FastAPI if needed# app = FastAPI()# app.mount("./static", StaticFiles(directory="static"), name="static")class DialogueItem(BaseModel):text: strspeaker: Literal["speaker-1", "speaker-2"]165 unmodified linestext_model = gr.Dropdown(label="Text Generation Model",choices=STANDARD_TEXT_MODELS,value="gpt-4o-mini",info="Select the model to generate the dialogue text.",)audio_model = gr.Dropdown(94 unmodified linesgr.Markdown(read_readme())# Enable queueing for better performancedemo.queue(max_size=20, default_concurrency_limit=20)# Launch the Gradio appif __name__ == "__main__":30 unmodified lines3132333435363738394041424344454647481 unmodified line50515253545556575859606162636465666768697071727374757677787980818283841 unmodified line868788899091929394959697989910010110210310410510610710810911011127 unmodified lines1391401411421431441451461471481491501511521 unmodified line1541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162176 unmodified lines22422522622722822923017 unmodified lines24824925025125225325425511 unmodified lines267268269270271272165 unmodified lines43843944044144244344494 unmodified lines53954054154254354454530 unmodified lines# Define multiple sets of instruction templatesINSTRUCTION_TEMPLATES = {################# PODCAST ##################"podcast": {"intro": """Your task is to take the input text provided and turn it into an lively, engaging, informative podcast dialogue, in the style of NPR. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages.Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that could be discussed in a podcast.Define all terms used carefully for a broad audience of listeners.""","text_instructions": "First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for a high quality presentation.","scratch_pad": """Brainstorm creative ways to discuss the main topics and key points you identified in the input text. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.Keep in mind that your podcast should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.1 unmodified lineWrite your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.Make sure to make it fun and exciting.""","prelude": """Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.""","dialog": """Write a very long, engaging, informative podcast dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience.Never use made-up names for the hosts and guests, but make it an engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.Make the dialogue as long and detailed as possible, while still staying on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest podcast episode you can, while still communicating the key information from the input text in an entertaining way.At the end of the dialogue, have the host and guest speakers naturally summarize the main insights and takeaways from their discussion. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas one last time before signing off.The podcast should have around 20000 words.""",},################# MATERIAL DISCOVERY SUMMARY ##################"material discovery summary": {"intro": """Your task is to take the input text provided and turn it into a lively, engaging conversation between a professor and a student in a panel discussion that describes a new material. The professor acts like Richard Feynman, but you never mention the name.The input text is the result of a design developed by SciAgents, an AI tool for scientific discovery that has come up with a detailed materials design.Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that could be discussed in a podcast.Define all terms used carefully for a broad audience of listeners.""","text_instructions": "First, carefully read through the input text and identify the main topics, key points, and any interesting facts or anecdotes. Think about how you could present this information in a fun, engaging way that would be suitable for a high quality presentation.","scratch_pad": """Brainstorm creative ways to discuss the main topics and key points you identified in the material design summary, especially paying attention to design features developed by SciAgents. Consider using analogies, examples, storytelling techniques, or hypothetical scenarios to make the content more relatable and engaging for listeners.Keep in mind that your description should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms.Use your imagination to fill in any gaps in the input text or to come up with thought-provoking questions that could be explored in the podcast. The goal is to create an informative and entertaining dialogue, so feel free to be creative in your approach.1 unmodified lineWrite your brainstorming ideas and a rough outline for the podcast dialogue here. Be sure to note the key insights and takeaways you want to reiterate at the end.Make sure to make it fun and exciting. You never refer to the podcast, you just discuss the discovery and you focus on the new material design only.""","prelude": """Now that you have brainstormed ideas and created a rough outline, it's time to write the actual podcast dialogue. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.""","dialog": """Write a very long, engaging, informative dialogue here, based on the key points and creative ideas you came up with during the brainstorming session. The presentation must focus on the novel aspects of the material design, behavior, and all related aspects.Use a conversational tone and include any necessary context or explanations to make the content accessible to a general audience, but make it detailed, logical, and technical so that it has all necessary aspects for listeners to understand the material and its unexpected properties.Remember, this describes a design developed by SciAgents, and this must be explicitly stated for the listeners.Never use made-up names for the hosts and guests, but make it an engaging and immersive experience for listeners. Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.Make the dialogue as long and detailed as possible, while still staying on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest podcast episode you can, while still communicating the key information from the input text in an entertaining way.At the end of the dialogue, have the host and guest speakers naturally summarize the main insights and takeaways from their discussion. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner. Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas one last time before signing off.The conversation should have around 20000 words."""},################# LECTURE ##################"lecture": {"intro": """You are Professor Richard Feynman. Your task is to develop a script for a lecture. You never mention your name.27 unmodified linesThere is only one speaker, you, the professor. Stay on topic and maintaining an engaging flow. Aim to use your full output capacity to create the longest lecture you can, while still communicating the key information from the input text in an engaging way.At the end of the lecture, naturally summarize the main insights and takeaways from the lecture. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner.Avoid making it sound like an obvious recap - the goal is to reinforce the central ideas covered in this lecture one last time before class is over.The lecture should have around 20000 words.""",},################# SUMMARY ##################"short summary": {"intro": """Your task is to develop a summary of a paper. You never mention your name.1 unmodified lineDefine all terms used carefully for a broad audience.""","text_instructions": "First, carefully read through the input text and identify the main topics, key points, and key facts. Think about how you could present this information in an accurate summary.","scratch_pad": """Brainstorm creative ways to present the main topics and key points you identified in the input text. Consider using analogies, examples, or hypothetical scenarios to make the content more relatable and engaging for listeners.Keep in mind that your summary should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms. Define all terms used clearly and spend effort to explain the background.Write your brainstorming ideas and a rough outline for the summary here. Be sure to note the key insights and takeaways you want to reiterate at the end.Make sure to make it engaging and exciting.""","prelude": """Now that you have brainstormed ideas and created a rough outline, it is time to write the actual summary. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.""","dialog": """Write a a script here, based on the key points and creative ideas you came up with during the brainstorming session. Use a conversational tone and include any necessary context or explanations to make the content accessible to the the audience.Start your script by stating that this is a summary, referencing the title or headings in the input text. If the input text has no title, come up with a succinct summary of what is covered to open.Include clear definitions and terms, and examples, of all key issues.Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.There is only one speaker, you. Stay on topic and maintaining an engaging flow.Naturally summarize the main insights and takeaways from the summary. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner.The summary should have around 1024 words.""",},################# SHORT SUMMARY ##################"short summary": {"intro": """Your task is to develop a summary of a paper. You never mention your name.Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points, identify definitions, and interesting facts that need to be summarized.Define all terms used carefully for a broad audience.""","text_instructions": "First, carefully read through the input text and identify the main topics, key points, and key facts. Think about how you could present this information in an accurate summary.","scratch_pad": """Brainstorm creative ways to present the main topics and key points you identified in the input text. Consider using analogies, examples, or hypothetical scenarios to make the content more relatable and engaging for listeners.Keep in mind that your summary should be accessible to a general audience, so avoid using too much jargon or assuming prior knowledge of the topic. If necessary, think of ways to briefly explain any complex concepts in simple terms. Define all terms used clearly and spend effort to explain the background.Write your brainstorming ideas and a rough outline for the summary here. Be sure to note the key insights and takeaways you want to reiterate at the end.Make sure to make it engaging and exciting.""","prelude": """Now that you have brainstormed ideas and created a rough outline, it is time to write the actual summary. Aim for a natural, conversational flow between the host and any guest speakers. Incorporate the best ideas from your brainstorming session and make sure to explain any complex topics in an easy-to-understand way.""","dialog": """Write a a script here, based on the key points and creative ideas you came up with during the brainstorming session. Keep it concise, and use a conversational tone and include any necessary context or explanations to make the content accessible to the the audience.Start your script by stating that this is a summary, referencing the title or headings in the input text. If the input text has no title, come up with a succinct summary of what is covered to open.Include clear definitions and terms, and examples, of all key issues.Do not include any bracketed placeholders like [Host] or [Guest]. Design your output to be read aloud -- it will be directly converted into audio.There is only one speaker, you. Stay on topic and maintaining an engaging flow.Naturally summarize the main insights and takeaways from the short summary. This should flow organically from the conversation, reiterating the key points in a casual, conversational manner.The summary should have around 256 words.""",},}6 unmodified linesINSTRUCTION_TEMPLATES[template]["scratch_pad"],INSTRUCTION_TEMPLATES[template]["prelude"],INSTRUCTION_TEMPLATES[template]["dialog"])import concurrent.futures as cfimport glob17 unmodified linesSTANDARD_TEXT_MODELS = ["o1-preview-2024-09-12","gpt-4o-2024-08-06","gpt-4o-mini","o1-mini-2024-09-12","openai/custom_model",]11 unmodified lines"shimmer",]class DialogueItem(BaseModel):text: strspeaker: Literal["speaker-1", "speaker-2"]165 unmodified linestext_model = gr.Dropdown(label="Text Generation Model",choices=STANDARD_TEXT_MODELS,value="o1-preview-2024-09-12", #"gpt-4o-mini",info="Select the model to generate the dialogue text.",)audio_model = gr.Dropdown(94 unmodified linesgr.Markdown(read_readme())# Enable queueing for better performancedemo.queue(max_size=20, default_concurrency_limit=32)# Launch the Gradio appif __name__ == "__main__":
app.py+77-50