File size: 3,058 Bytes
ef0dcda
 
 
0259995
aebc2c9
 
ef0dcda
 
aebc2c9
 
 
0259995
ef0dcda
0259995
aebc2c9
 
 
 
 
 
 
 
 
 
 
ef0dcda
aebc2c9
 
 
 
0259995
ef0dcda
0259995
a633d8d
0259995
ef0dcda
0259995
88d1499
ef0dcda
0259995
ef0dcda
0259995
 
ef0dcda
aebc2c9
ef0dcda
87a3eaa
aebc2c9
0259995
 
aebc2c9
5fd684e
aebc2c9
5fd684e
aebc2c9
 
 
 
 
 
 
 
0259995
aebc2c9
636bc65
208b15e
 
636bc65
 
 
 
 
 
 
 
 
aebc2c9
 
 
 
ef0dcda
465135d
aebc2c9
 
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
# coding=utf8
from gpt_index import SimpleDirectoryReader, GPTListIndex, GPTSimpleVectorIndex, LLMPredictor, PromptHelper
from langchain import OpenAI
import gradio as gr
import random
import time
import sys
import os
from transformers import pipeline
p = pipeline("automatic-speech-recognition")


os.environ["OPENAI_API_KEY"] = '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'

md = """This is some code:

hello

```py
def fn(x, y, z):
    print(x, y, z)
"""
def transcribe(audio):
    text = p(audio)["text"]
    return text
def construct_index(directory_path):
    max_input_size = 10000
    num_outputs = 10000
    max_chunk_overlap = 20000
    chunk_size_limit = 600000

    prompt_helper = PromptHelper(max_input_size, num_outputs, max_chunk_overlap, chunk_size_limit=chunk_size_limit)

    llm_predictor = LLMPredictor(llm=OpenAI(temperature=0.0, model_name="text-davinci-003", max_tokens=num_outputs))

    documents = SimpleDirectoryReader(directory_path).load_data()

    index = GPTSimpleVectorIndex.from_documents(documents)
    index.save_to_disk('index.json')

    return index


def chatbot(input_text):

    index = GPTSimpleVectorIndex.load_from_disk('index.json')
    response = index.query(input_text)
    return str(response.response)


with gr.Blocks() as demo:
    gpt = gr.Chatbot(label="Zoh", elem_id="chatbot").style(height=800)
    msg = gr.Textbox( show_label=False,
                placeholder="Bem vindo ao Hippo Supermercados, em que posso ajuda-lo?",
            ).style(container=False)
    clear = gr.Button("Limpar Conversa")
    gr.Audio(source="microphone", type="filepath",label="ESTÁ COM DIFICULDADES EM ESCREVER? CLIQUE E ME DIGA O QUE DESEJA")
    def respond(message, chat_history):
        chat_history.append((message, chatbot(message)))
        time.sleep(1)
        vetor = []
        realPath = str(os.path.dirname(os.path.realpath(__file__)))

        if str(message).upper()=="OLA" or str(message).upper()=="OLÁ" or str(message).upper()=="OI":
            vetor = vetor + [((realPath + "\\images\\logo.png",), "")]
        elif str(message).upper() == "VINHO CASA DEL RONCO PINOT GRIGIO" :
                vetor = vetor + [((realPath + "\\images\\casa-del-ronco-branco.png",), "")]
        elif str(message).upper() == "VINHO SURVIVOR CHENIN BLANC" :
                vetor = vetor + [((realPath + "\\images\\survivor-branco.png",), "")]
        elif str(message).upper() == "VINHO PORTO NOVA VERDE" :
                vetor = vetor + [((realPath + "\\images\\porta-nova-branco.jpg",), "")]
        elif str(message).upper() == "VINHO QUINTA DO PINTO ARINTO BRANCO" :
                vetor = vetor + [((realPath + "\\images\\quinta-pinto-arinto-branco.png",), "")]
        elif str(message).upper() == "VINHO 1492 CHARDONNAY" :
                vetor = vetor + [((realPath + "\\images\\chardonay-branco.jpg",), "")]

        return "", chat_history+vetor

    clear.click(lambda:None, None, gpt, queue=False,)
    msg.submit(respond, [msg, gpt], [msg,gpt])

index = construct_index("docs")
demo.launch()