File size: 2,060 Bytes
ba34941
 
 
fd28f98
ba34941
fd28f98
 
ba34941
fd28f98
 
 
ba34941
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51e6bb4
 
352048d
 
ba34941
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c47e962
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
import gradio as gr
import pickle
from chain import get_chain
from ingest import ingest_data

global vectorstore
vectorstore = ingest_data()

# with open("db.pkl", "rb") as f:
#     global vectorstore
#     vectorstore = pickle.load(f)

chain = get_chain()

def chat(inp, history):
    history = history or []
    output = chain({'input_documents': vectorstore.similarity_search(inp, k=4), 'query': inp}, return_only_outputs=True)
    response = output['output_text']
    history.append((inp, response))
    return history, history


block = gr.Blocks(css=".gradio-container {background-color: lightgray}")

with block:
    with gr.Row():
        with gr.Column(scale=1):
            gr.Markdown("""<img src=https://huggingface.co/spaces/sooolee/beer-sommelier/resolve/main/images/octo.jpeg width=150></left>""")
        with gr.Column(scale=20):
            gr.Markdown("<h2><left>\"Hi! Welcome to Gourmet Haus Staudt!!\"</left></h2>")
            gr.Markdown("<h2><left>\"I'm your Beer Sommelier, and here to help you choose the right beer for you!\"</left></h2>")

    chatbot = gr.Chatbot()

    with gr.Row():
        message = gr.Textbox(
            label="What's your question?",
            placeholder="Do you have any recommendations for IPA with tropical fruite flavors?",
            lines=1,
        )
    with gr.Row():
        submit = gr.Button(value="Send", variant="secondary", size="lg")

    gr.Examples(
        examples=[
            "What does Bock taste like? Do you recommend it?",
            "I like Lagunitas IPA. Do you have anything similar?",
            "Do you have any recommendations for Pilsner?",
            "What kind of German beers do you have?"
        ],
        inputs=message,
    )

    state = gr.State()

    message.submit(chat, inputs=[message, state], outputs=[chatbot, state])
    message.submit(lambda x: gr.update(value=''), [], [message])

    submit.click(chat, inputs=[message, state], outputs=[chatbot, state])
    submit.click(lambda x: gr.update(value=''), [], [message])


block.launch(debug=True)