File size: 1,185 Bytes
8c2963b
2d65d8a
0d80d9a
866cd37
 
 
 
 
 
 
 
fac9ba9
 
 
 
 
866cd37
 
0d80d9a
2d65d8a
bfa4f0f
2d65d8a
 
8c2963b
 
 
 
 
 
 
 
 
 
866cd37
8c2963b
 
 
 
 
866cd37
8c2963b
 
 
 
 
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
import gradio as gr
from TwitterChatBot.main import ask

title = "Car Seats Voice Commands"

link = "https://cdn.cms-twdigitalassets.com/content/dam/legal-twitter/asset-download-files/TheTwitterUserAgreement_1.pdf"

description = f"""
# Twitter Terms Of Service ChatBot
This chatbot answers questions about **Twitter terms of service** based on this [resource]({link}), The techniques used in this project
can be used to answer questions from any kind of business or legal document.

### Examples:
try something like
- What is twitter?
- What actions are permitted for the users?
"""


def get_answer(question):
    print(question)
    answer = ask(question=question)
    return answer.strip()


def predict(input, history=[]):
    answer = get_answer(input)
    history.append((input, answer))
    response = history
    return response, history


with gr.Blocks() as demo:
    gr.Markdown(description)
    chatbot = gr.Chatbot()
    state = gr.State([])

    with gr.Row():
        txt = gr.Textbox(
            show_label=False, placeholder="Ask me a question and press enter"
        ).style(container=False)

    txt.submit(predict, [txt, state], [chatbot, state])

demo.launch()