File size: 3,529 Bytes
0b2e50a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9328989
0b2e50a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c37cb9
 
0b2e50a
 
 
 
 
 
 
 
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
import gradio as gr
import time
import json
import os

from PIL import Image
from gradio_client import Client
from dataclasses import dataclass


hf_key = os.environ['HF_API_KEY']

client = Client("amitagh/BC-Chat-pvt", hf_token=hf_key)
def get_cust_rsp(history, text):

  result = client.predict(
		history=history,
		text=text,
		api_name="/handle_user_ques"
  )
  print(result)

  return result
    
def handle_user_ques(history, text):
    start_time = time.time()

    llm_response = get_cust_rsp(history,text)

    history.append((text, llm_response))
    # Calculate and print elapsed time
    end_time = time.time()
    felapsed_time = end_time - start_time
    print(f"Text LLM rsp Execution time: {felapsed_time:.4f} seconds")

    start_time = time.time()

    audio_file_path = ""
    #audio_file_path = convet_tts(llm_response)

    # Calculate and print elapsed time
    end_time = time.time()
    felapsed_time = end_time - start_time
    print(f"TTS rsp Execution time: {felapsed_time:.4f} seconds")

    #return history, "", audio_file_path
    return history, ""


def clear_chat(history, text):
    """
    Resets the chat history and the lead object.
    Args:
        history (str): The current chat history.
        text (str): The current text.
    Returns:
        tuple: A tuple of two empty strings.
    """
    history = ""
    return "", ""

# Create the Gradio interface
with gr.Blocks() as bc_chatbot:
    #gr.set_static_paths(paths=["."])
    #image_path = "Shivneri-Chat-Banner.png"

    #gr.HTML(f"""<img src="/file={image_path}" width="750" height="300">""")
    gr.Markdown(value="## BC Chatbot")
    with gr.Row():
        with gr.Column(scale=1):
          chatbot = gr.Chatbot(value=[], label="BC")


          txt = gr.Textbox(
                label="Input your question:",
                placeholder="Enter text and press enter",
            )    #.style(container=False)
          examples = gr.Examples(
            label="Question examples",
            examples=[["What is this book about?"], ["What is Ashram?"], ["What are the different Ashrams?"], ["What is Bramhacharya?"],
                  ["What is Grihastha?"], ["What is Vanaprastha?"], ["What is Sannyasa?"], ["What are key takeaways of each stage?"], ["what is the importance of shlokas in Bhagwadgita?"],
                  ["What are the different types of dialogues?"], ["On personal life how can shlokas help?"]],
                  #["Too slow & Time consuming"], ["Fully automated, consistent"], ["Hired more people, but that is costly. Tried a automated solution but it was complex and is inconsistent"],],
                  inputs=[txt],)
          #output_audio = gr.Audio(autoplay=True, visible=False)
          btn = gr.Button("Submit")

          clear_btn = gr.Button("Clear Chat")

          #app_txt = gr.Textbox(label = "App info", interactive=False)
          #app_but = gr.Button("App info")
          #app_but.click(
          #    app_inst.get_app_info,
          #    inputs=[],
          #    outputs=[app_txt],
          #)


          #txt.submit(handle_customer_response, [chatbot, txt], [chatbot, txt, output_audio])
          #btn.click(handle_customer_response, [chatbot, txt], [chatbot, txt, output_audio])
          txt.submit(get_cust_rsp, [chatbot, txt], [chatbot, txt])
          btn.click(get_cust_rsp, [chatbot, txt], [chatbot, txt])
          clear_btn.click(
            clear_chat,
            [chatbot, txt], [chatbot, txt]
          )


bc_chatbot.queue()
bc_chatbot.launch(debug=True)