Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from llm_call import GeminiLLM | |
| from seminar_edition_ai import upload_file_ex, predictContemplando, predictProclamando, predictFromInit, \ | |
| downloadSermonFile, fileAddresToDownload, predictQuestionBuild, predictDevotionBuild, \ | |
| contemplandoQuestion, proclamandoQuestion, llm, embed_model | |
| HISTORY_ANSWER = '' | |
| def activeSermonGuideZone(KEY): | |
| #print("Button show " + buttonEvent.label) | |
| return {text_button: gr.update (interactive = True), question_option: [KEY]} | |
| def showMessage(questionAnswer, KEY): | |
| if questionAnswer == None or questionAnswer == '' or len(questionAnswer) <= 7: | |
| raise gr.Error(f"You must write some answer or more longer {KEY}") | |
| raise gr.Error(f" No implemented yet {KEY}!!!") | |
| with gr.Blocks() as demo: | |
| gr.Markdown("SermonLab AI Demo.") | |
| with gr.Tab("Preparando mi Serm贸n"): | |
| text_input = gr.Textbox(label="T贸pico del serm贸n") | |
| text_output = gr.Textbox(label="Respuesta", lines=10) | |
| text_button = gr.Button("Crear") | |
| text_download = gr.DownloadButton( | |
| label="Descargar", | |
| value=fileAddresToDownload, | |
| every=10 | |
| ) | |
| text_button.click( | |
| fn=predictFromInit, | |
| inputs=text_input, | |
| outputs=text_output | |
| ) | |
| text_download.click( | |
| fn=downloadSermonFile, | |
| inputs=text_output | |
| ) | |
| with gr.Tab("Obtener gu铆a de la comunidad (Preguntas)"): | |
| with gr.Accordion("Contemplando y Proclamando", open=False): | |
| checkButton = gr.Checkbox( | |
| value=False, | |
| label="Mantener historial" | |
| ) | |
| with gr.Row(): | |
| with gr.Tab("Contemplando"): | |
| inbtwContemplando = gr.Button(f"Devocionalmente: {contemplandoQuestion['DEVOCIONALMENTE']}") | |
| inbtwContemplandoOne = gr.Button(f"Ex茅gesis: {contemplandoQuestion['EX脡GESIS']}") | |
| inbtwContemplandoTwo = gr.Button(f"Cristo: {contemplandoQuestion['CRISTO']}") | |
| inbtwContemplandoTree = gr.Button(f"Arco Redentor: {contemplandoQuestion['ARCO REDENTOR']}") | |
| inbtwContemplandoFour = gr.Button(f"Evangeli贸n: {contemplandoQuestion['EVANGELION']}") | |
| inbtwContemplandoFourOne = gr.Button(f"Evangeli贸n: {contemplandoQuestion['EVANGELION_TWO']}") | |
| with gr.Tab("Proclamando"): | |
| inbtwProclamando = gr.Button(f"P煤blico: {proclamandoQuestion['P脷BLICO']}") | |
| inbtwProclamandoOne = gr.Button(f"Historia: {proclamandoQuestion['HISTORIA']}") | |
| inbtwProclamandoTwo = gr.Button(f"Expectativas: {proclamandoQuestion['EXPECTATIVAS']}") | |
| inbtwProclamandoTwoTwo = gr.Button(f"Expectativas: {proclamandoQuestion['EXPECTATIVAS_TWO']}") | |
| with gr.Row(): | |
| #Bibliografy about components | |
| # File (https://www.gradio.app/docs/gradio/file) | |
| # Download Button (https://www.gradio.app/docs/gradio/downloadbutton) | |
| with gr.Column(): | |
| file_input_question = gr.File() | |
| upload_button_question = gr.UploadButton("Click to Upload a File", file_types=['.pdf'], | |
| file_count="multiple") | |
| with gr.Column(): | |
| temp_slider_question = gr.Slider( | |
| minimum=1, | |
| maximum=10, | |
| value=1, | |
| step=1, | |
| interactive=True, | |
| label="Preguntas", | |
| ) | |
| text_output_question = gr.Textbox(label="Respuesta", lines=10) | |
| text_button_question = gr.Button("Crear gu铆a de preguntas") | |
| text_download_question = gr.DownloadButton( | |
| label="Descargar", | |
| value=fileAddresToDownload, | |
| every=10 | |
| ) | |
| text_button_question.click( | |
| fn=predictQuestionBuild, | |
| outputs=text_output_question | |
| ) | |
| upload_button_question.upload(upload_file_ex, inputs=upload_button_question, | |
| outputs=[file_input_question, text_output_question]) | |
| with gr.Tab("Obtener gu铆a de la comunidad (Devocionario)"): | |
| with gr.Row(): | |
| #Bibliografy about components | |
| # File (https://www.gradio.app/docs/gradio/file) | |
| # Download Button (https://www.gradio.app/docs/gradio/downloadbutton) | |
| with gr.Column(): | |
| file_input_devotions = gr.File() | |
| upload_button_devotion = gr.UploadButton("Click to Upload a File", file_types=['.pdf'], | |
| file_count="multiple") | |
| with gr.Column(): | |
| temp_slider_question = gr.Slider( | |
| minimum=1, | |
| maximum=10, | |
| value=1, | |
| step=1, | |
| interactive=True, | |
| label="Cantidad", | |
| ) | |
| text_output_devotions = gr.Textbox(label="Respuesta", lines=10) | |
| text_button_devotion = gr.Button("Crear") | |
| text_download_question = gr.DownloadButton( | |
| label="Descargar", | |
| value=fileAddresToDownload, | |
| every=10 | |
| ) | |
| text_button_devotion.click( | |
| fn=predictDevotionBuild, | |
| outputs=text_output_devotions | |
| ) | |
| upload_button_devotion.upload( | |
| upload_file_ex, | |
| inputs=upload_button_devotion, | |
| outputs= | |
| [file_input_devotions, text_output_devotions] | |
| ) | |
| with gr.Tab("Contemplando y Proclamando (Gu铆a de preguntas)"): | |
| question_option = gr.State([]) | |
| with gr.Accordion("Contemplando y Proclamando", open = False): | |
| checkButton = gr.Checkbox( | |
| value=False, | |
| label="Mantener historial" | |
| ) | |
| with gr.Row(): | |
| with gr.Tab("Contemplando"): | |
| inbtwContemplando = gr.Button(f"Devocionalmente: {contemplandoQuestion['DEVOCIONALMENTE']}") | |
| inbtwContemplandoOne = gr.Button(f"Ex茅gesis: {contemplandoQuestion['EX脡GESIS']}") | |
| inbtwContemplandoTwo = gr.Button(f"Cristo: {contemplandoQuestion['CRISTO']}") | |
| inbtwContemplandoTree = gr.Button(f"Arco Redentor: {contemplandoQuestion['ARCO REDENTOR']}") | |
| inbtwContemplandoFour = gr.Button(f"Evangeli贸n: {contemplandoQuestion['EVANGELION']}") | |
| inbtwContemplandoFourOne = gr.Button(f"Evangeli贸n: {contemplandoQuestion['EVANGELION_TWO']}") | |
| with gr.Tab("Proclamando"): | |
| inbtwProclamando = gr.Button(f"P煤blico: {proclamandoQuestion['P脷BLICO']}") | |
| inbtwProclamandoOne = gr.Button(f"Historia: {proclamandoQuestion['HISTORIA']}") | |
| inbtwProclamandoTwo = gr.Button(f"Expectativas: {proclamandoQuestion['EXPECTATIVAS']}") | |
| inbtwProclamandoTwoTwo = gr.Button(f"Expectativas: {proclamandoQuestion['EXPECTATIVAS_TWO']}") | |
| with gr.Row(): | |
| with gr.Column(scale = 2): | |
| #Answer for Contemplando y Proclamando questions | |
| text_output_guia = gr.Textbox(label="Respuesta", lines = 10) | |
| with gr.Column(scale = 1, min_width = 200): | |
| text1 = gr.Textbox(visible = False) | |
| #Button for calling AI Help | |
| text_button = gr.Button("Buscar m谩s informaci贸n (IA)", | |
| min_width = 200, | |
| interactive = False | |
| ) | |
| text2 = gr.Textbox(visible = False) | |
| with gr.Column(scale = 2): | |
| text_output_aiAnswer = gr.Textbox(label="Ayuda a mi respuesta", lines = 10) | |
| inbtwContemplando.click( | |
| fn = lambda x: activeSermonGuideZone(contemplandoQuestion['DEVOCIONALMENTE']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwContemplandoOne.click( | |
| fn = lambda x: activeSermonGuideZone(contemplandoQuestion['EX脡GESIS']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwContemplandoTwo.click( | |
| fn = lambda x: activeSermonGuideZone(contemplandoQuestion['CRISTO']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwContemplandoTree.click( | |
| fn = lambda x: activeSermonGuideZone(contemplandoQuestion['ARCO REDENTOR']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwContemplandoFour.click( | |
| fn = lambda x: activeSermonGuideZone(contemplandoQuestion['EVANGELION']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwContemplandoFourOne.click( | |
| fn = lambda x: activeSermonGuideZone(contemplandoQuestion['EVANGELION_TWO']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| #####--------------------------------------------------------------------------------------------------------- | |
| inbtwProclamando.click( | |
| fn = lambda x: activeSermonGuideZone(proclamandoQuestion['P脷BLICO']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwProclamandoOne.click( | |
| fn = lambda x: activeSermonGuideZone(proclamandoQuestion['HISTORIA']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwProclamandoTwo.click( | |
| fn = lambda x: activeSermonGuideZone(proclamandoQuestion['EXPECTATIVAS']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| inbtwProclamandoTwoTwo.click( | |
| fn = lambda x: activeSermonGuideZone(proclamandoQuestion['EXPECTATIVAS_TWO']), | |
| inputs = inbtwContemplandoOne, | |
| outputs = [text_button, question_option] | |
| ) | |
| text_button.click(fn = showMessage, inputs = [text_output_guia, question_option], outputs = text_output_aiAnswer) | |
| if __name__ == "__main__": | |
| llmBuilder = GeminiLLM() | |
| embed_model = llmBuilder.getEmbeddingsModel() | |
| llm = llmBuilder.getLLM() | |
| demo.launch(share=True) | |