Spaces:
Runtime error
Runtime error
File size: 5,210 Bytes
439340a 74e5ab2 cf91c74 439340a 74e5ab2 439340a cf91c74 439340a cf91c74 439340a a640dcc 4c87232 a640dcc 439340a cf91c74 439340a 4c87232 cf91c74 a640dcc cf91c74 c380b7b 439340a cf91c74 4c87232 cf91c74 439340a c380b7b 439340a cf91c74 4c87232 cf91c74 439340a c380b7b 439340a cf91c74 c380b7b cf91c74 439340a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
import gradio as gr
import os
from gcp import download_credentials
from utils import make_invisible, make_visible, create_folders
from backend_functions import get_answer, init_greeting, export_dataframe
from dotenv import load_dotenv
load_dotenv()
download_credentials()
create_folders()
with gr.Blocks() as main_app:
with gr.Tab('Chatbot'):
user_id = gr.State('') # id used to find the chat into the database
with gr.Column():
with gr.Row():
chat = gr.Chatbot(label="Chatbot Crunchyroll")
output_video = gr.Video(interactive=False, label='Video', autoplay=True, height=400)
with gr.Column():
with gr.Row():
options_audio = gr.Radio(["XTTS", "Elevenlabs"], value="Elevenlabs", label="Audio Generation")
options_prompt = gr.Radio(["Default", "Custom"], value="Default", label="Prompts")
output_audio = gr.Audio(interactive=False, label='Audio', autoplay=False)
messages = gr.State([])
with gr.Row():
text = gr.Textbox(label='Write your question')
with gr.Column():
with gr.Row():
button_text = gr.Button(value='Submit text')
clear_button = gr.ClearButton([chat, messages])
with gr.Tab('Prompts'):
general_prompt = gr.Text(
placeholder='Ingrese el prompt general del bot', label='General prompt'
)
standalone_prompt = gr.Text(
placeholder='Ingrese el prompt usado para encontrar el contexto', label='Standalone prompt'
)
_ = gr.Markdown(
"```\n"
"Recuerde dejar estos formatos en los prompts: \n"
"----------------------- General --------------------------\n"
"=========\n"
"Contexto:\n"
"CONTEXTO\n"
"=========\n"
"\n"
"----------------------- Standalone -----------------------\n"
"You are a standalone question-maker. Given the following chat history and follow-up message, rephrase "
"the follow-up phrase to be a standalone question (sometimes the follow-up is not a question, so create "
"a standalone phrase), in spanish. In the standalone message you must include all the information at the "
"moment that is known about the customer, all the important nouns and what they are looking for. In cases "
"where you think is usefully, include what is the best recommendation for the customer. To give you "
"context, the conversation is about (INGRESE INFORMACIÓN DE LA MARCA, EL NOMBRE Y DE MANERA MUY GENERAL "
"QUE ES LO QUE VENDE).\n"
"There might be moments when there isn't a question in those cases return a standalone phrase: for example "
"if the user says 'hola' (or something similar) then the output would be 'el usuario está saludando', or "
"if the user says 'gracias' or 'es muy util' (or something similar) then the output would be a phrase "
"showing that the user is grateful and what they are grateful for, or if the user say 'si' then it would "
"be a phrase encapsulating the relationship to its previous question or phrase.\n"
"Your response cannot be more than 100 words.\n"
"Chat History:\n"
"\n"
"HISTORY\n"
"Follow-up message: QUESTION\n"
"Standalone message:\n", line_breaks=True
)
with gr.Tab('Times'):
columns = ["User Message", "Chatbot Response", "Standalone Question", "Create Embedding", "Query Pinecone",
"Context Prompt", "Final Response GPT", "Create Clean Message", "Create Audio", "Create Video", "Final Time"]
table_times = gr.DataFrame(headers=columns, visible=False, interactive=False)
with gr.Column():
with gr.Row(visible=False) as row_export_csv:
export_button = gr.Button(value="Export CSV")
csv = gr.File(interactive=False, visible=False)
text.submit(
fn=get_answer,
inputs=[text, chat, messages, output_audio, output_video, table_times, options_audio, options_prompt, general_prompt, standalone_prompt],
outputs=[chat, output_audio, output_video, table_times]
).then(
lambda: None, None, [text]
).then(
fn=make_visible,
inputs=None,
outputs=row_export_csv
)
button_text.click(
fn=get_answer,
inputs=[text, chat, messages, output_audio, output_video, table_times, options_audio, options_prompt, general_prompt, standalone_prompt],
outputs=[chat, output_audio, output_video, table_times]
).then(
lambda: None, None, [text]
).then(
fn=make_visible,
inputs=None,
outputs=row_export_csv
)
export_button.click(
fn=export_dataframe,
inputs=table_times,
outputs=csv
)
main_app.load(init_greeting, inputs=[chat, messages], outputs=[chat, messages])
main_app.launch(debug=True, auth=(os.environ.get('SPACE_USERNAME'), os.environ.get('SPACE_PASSWORD'))) |