File size: 1,699 Bytes
93f7d2b
6f7c81e
93f7d2b
6f7c81e
f3fe590
6f7c81e
 
93f7d2b
 
6f7c81e
 
 
 
 
 
 
 
93f7d2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f7c81e
93f7d2b
 
 
 
 
6f7c81e
93f7d2b
 
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
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load the model and tokenizer
model_name = "google/flan-t5-xxl"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Define the chat function
def chat(message):
    # Encode the user's message
    inputs = tokenizer.encode(message, return_tensors="pt")
    # Generate a response from the model
    outputs = model.generate(inputs, max_length=1024, pad_token_id=tokenizer.eos_token_id)
    response = tokenizer.decode(outputs[0], skip_special_tokens=True)
    # Return the response
    return response

# Set up the Gradio interface
block = gr.Blocks(css=".gradio-container {background-color: lightgray}")

with block:
    with gr.Row():
        gr.Markdown("<h3><center>SplitticAI Chatbot</center></h3>")

    chatbot = gr.Chatbot()

    with gr.Row():
        message = gr.Textbox(
            label="What's your question?",
            placeholder="What would you like to ask me?",
            lines=1,
        )
        submit = gr.Button(value="Send", variant="secondary").style(full_width=False)

    gr.Examples(
        examples=[
            "What is artificial intelligence?",
            "How does SplitticAI work?",
            "Can you tell me a joke?",
        ],
        inputs=message,
    )

    gr.HTML("Ask SplitticAI anything and get an answer!")

    gr.HTML(
        "<center>Powered by <a href='https://huggingface.co/google/flax-t5-xxl-qa-121k'>google/flax-t5-xxl-qa-121k</a></center>"
    )

    state = gr.State()
    agent_state = gr.State()

    submit.click(chat, inputs=[message], outputs=[chatbot])

block.launch(debug=True)