Spaces:
Runtime error
Runtime error
File size: 7,943 Bytes
ef0dcda 0259995 aebc2c9 ef0dcda aebc2c9 0259995 ef0dcda 0259995 0b5be0e 6300de6 0b5be0e 6300de6 f83142c 0b5be0e 6300de6 0b5be0e fa2273f 6300de6 fa2273f 6300de6 fa2273f 6300de6 0b5be0e 6300de6 0b5be0e 6300de6 0b5be0e 6300de6 f83142c 0b5be0e f83142c 0b5be0e 6300de6 f83142c fa2273f f83142c fa2273f f83142c 0b5be0e aebc2c9 ef0dcda aebc2c9 fa2273f aebc2c9 0259995 ef0dcda 0259995 a633d8d 0259995 ef0dcda 0259995 88d1499 ef0dcda 0259995 ef0dcda 0259995 ef0dcda aebc2c9 ef0dcda 87a3eaa aebc2c9 0259995 6300de6 0b5be0e 6300de6 5fd684e aebc2c9 6130bf8 aebc2c9 0259995 aebc2c9 fba0c50 208b15e 16cf4cd 636bc65 51eca97 636bc65 51eca97 636bc65 9b30fcd 51eca97 42c71f8 b78589d fc09e21 3f3101f 51eca97 b78589d fc09e21 636bc65 aebc2c9 6130bf8 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 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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# 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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'
css = """
.gradio-container {
background-color: #ffffff;
}
#component-2 {position: absolute; bottom: 0; width: 100%;
}
div.float.svelte-1frtwj3 {
position: absolute;
opacity: 0;
top: var(--block-label-margin);
left: var(--block-label-margin);}
.wrap.svelte-6roggh.svelte-6roggh {
padding: var(--block-padding);
height: 100%;
max-height: 100%;
overflow-y: auto;
}
div.svelte-1frtwj3 {
display: inline-flex;
align-items: center;
z-index: var(--layer-2);
box-shadow: var(--block-shadow);
border: var(--block-label-border-width) solid #ffffff;
border-top: none;
border-left: none;
border-radius: var(--block-label-radius);
background: #eff6ff;
padding: var(--block-label-padding);
pointer-events: none;
color: var(--block-label-text-color);
font-weight: var(--block-label-text-weight);
width: 100%;
line-height: var(--line-sm);
}
div.bot.svelte-6roggh.svelte-6roggh {
background: #D9A13D;
}
div.bot.svelte-17nzccn.svelte-17nzccn {
background: #D9A13D;
}
div.user.svelte-6roggh.svelte-6roggh {
background: #5F0000;
}
div.user.svelte-17nzccn.svelte-17nzccn {
background: #5F0000;
}
div.textBoxBot {
display: flex;
flex-direction: inherit;
flex-wrap: wrap;
gap: var(--form-gap-width);
box-shadow: var(--block-shadow);
border: var(--block-border-width) solid #5f0000;
border-radius: var(--radius-lg);
background: #ffffff;
overflow: hidden;
position: fixed;
bottom: 0;
margin-left: -16px;
}
.textarea.svelte-1pie7s6.svelte-1pie7s6 {
display: flex;
flex-direction: inherit;
flex-wrap: wrap;
gap: var(--form-gap-width);
box-shadow: var(--block-shadow);
border: var(--block-border-width) solid #5f0000;
border-radius: var(--radius-lg);
background: #ffffff;
overflow: hidden;
position: fixed;
bottom: 0;
margin-left: -16px;
}
.svelte-1pie7s6.svelte-1pie7s6 {
display: flex;
flex-direction: inherit;
flex-wrap: wrap;
gap: var(--form-gap-width);
box-shadow: var(--block-shadow);
border: 5px solid #5f0000;
border-radius: var(--radius-lg);
border-color: #5F0000;
background: #ffffff;
color: #5F0000;
font-size: 16px;
overflow: hidden;
position: fixed;
bottom: 20px; /* Ajuste a distância vertical do rodapé */
margin-left: -5px;
max-height: 80vh; /* Ajuste a altura máxima da div */
max-width: 78%; /* Ajuste a largura máxima da div */
}
.img.svelte-ms5bsk {
width: 100%;
height: 100%;
background-color: #ffffff;
border: 0px;
border-width: 0px;
}
.app.svelte-ac4rv4.svelte-ac4rv4 {
max-width: none;
background-color: #ffffff;
}
.app.svelte-ac4rv4.svelte-ac4rv4{max-width:none}
.wrap.svelte-1o68geq.svelte-1o68geq {max-height: none}
.block.svelte-mppz8v {
position: relative;
margin: 0;
box-shadow: var(--block-shadow);
border-width: var(--block-border-width);
border-color: #ffffff;
border-radius: var(--block-radius);
background: #ffffff;
width: 100%;
line-height: var(--line-sm);
}
"""
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 = 20000
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(css=css) as demo:
realPath = str(os.path.dirname(os.path.realpath(__file__)))
img1 = gr.Image("images/1024x150_cabeçalho.hippo.png", elem_classes=".img.svelte-ms5bsk", elem_id="img.svelte-ms5bsk").style(container=False)
gpt = gr.Chatbot(elem_classes=".wrap.svelte-1o68geq.svelte-1o68geq", elem_id="chatbot").style(container=True)
msg = gr.Textbox(elem_id="div.svelte-awbtu4",elem_classes="textBoxBot", 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\\hippo-apresentacao.mp4",), "")]
elif str(message).upper() == "VINHO CASA DEL RONCO PINOT GRIGIO" :
vetor = vetor + [((realPath + "\\images\\casa-del-ronco-branco.png",), "")]
elif str(message).upper() == "SURVIVOR CHENIN BLANC" :
vetor = vetor + [((realPath + "\\images\\survivor-branco.png",), "")]
vetor = vetor + [((realPath + "\\images\\survivor.mp4",), "")]
elif str(message).upper() == "VINHO PORTO NOVA VERDE" :
vetor = vetor + [((realPath + "\\images\\porta-nova-branco.jpg",), "")]
vetor = vetor + [((realPath + "\\images\\porta-nova-verde.mp4",), "")]
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",), "")]
elif str(message).upper() == "ME SUGIRA UM VINHO TINTO BOM COM QUEIJO" :
vetor = vetor + [((realPath + "\\images\\TNT-CABERNET.png",), "")]
vetor = vetor + [((realPath + "\\images\\vinho-queijo.mp4",), "")]
elif str(message).upper() == "VINHO BOM COM CHOCOLATE" :
vetor = vetor + [((realPath + "\\images\\TNT-CABERNET.png",), "")]
elif str(message).upper() == "VINHO BOM COM PEIXE" :
vetor = vetor + [((realPath + "\\images\\luson-branco.png",), "")]
vetor = vetor + [((realPath + "\\images\\vinho-peixe.mp4",), "")]
elif str(message).upper() == "VINHAS DO LASSO COLHEITA SELECIONADA" :
vetor = vetor + [((realPath + "\\images\\lasso-colheita-rose.png",), "")]
elif str(message).upper() == "DOM CAMPOS MOSCATEL" :
vetor = vetor + [((realPath + "\\images\\dom-campos-rose.png",), "")]
elif str(message).upper() == "BECAS ROSE MEIO SECO" :
vetor = vetor + [((realPath + "\\images\\becas-rose.png",), "")]
elif str(message).upper() == "PORTA DA RAVESSA" :
vetor = vetor + [((realPath + "\\images\\luson-branco.png",), "")]
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()
|