File size: 3,155 Bytes
f978a18
a6ea74a
ede9186
 
 
 
a7d738c
f978a18
 
 
 
 
 
 
ddc827d
 
a6ea74a
c7e4dc7
 
 
 
 
 
 
994d521
4f17f58
c7e4dc7
a6ea74a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ecba286
a6ea74a
f978a18
a6ea74a
f978a18
 
a6ea74a
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
import gradio as gr

from src.model_loader import load_model
from src.retriever import setup_retriever
from src.llm_chain import setup_llm_chain
from src.utils import generate_response
from langchain_core.runnables import RunnablePassthrough
from huggingface_hub import InferenceClient

"""
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
"""
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")



def main():
    # Load necessary components
    retriever = setup_retriever()
    llm_chain = setup_llm_chain()
    # Set up retrieval-augmented generation chain
    rag_chain = (
        {"context": retriever, "question": RunnablePassthrough()}
        | llm_chain)

    interface = gr.Interface(
        fn=lambda question: generate_response(question, rag_chain),
        inputs=gr.Textbox(placeholder="Ask your question...", label="Your Question", lines=2),
        outputs=gr.Textbox(label="Bloodraven's Response", lines=5, interactive=False),
        title="Bloodraven Chatbot",
        description="Ask any question and receive cryptic, prophetic answers from the Bloodraven from A Song of Ice and Fire.",
        css="""
            .gradio-container {
                font-family: 'Arial', sans-serif;  /* Simple, clear font */
                background-color: #f9f9f9;  /* Light gray background */
                color: #333333;  /* Dark gray text for contrast */
            }
            .input_textbox, .output_textbox {
                border-radius: 5px;  /* Rounded corners */
                border: 2px solid #007bff;  /* Bright blue border */
                background-color: #ffffff;  /* White background for input/output boxes */
                color: #333333;  /* Dark gray text for visibility */
                box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);  /* Subtle shadow */
            }
            .input_textbox:focus, .output_textbox:focus {
                border-color: #ff4500;  /* Bright orange-red border on focus */
            }
            .title {
                font-size: 36px;  /* Larger title */
                font-weight: bold;  /* Bold title */
                text-align: center;  /* Centered title */
                color: #007bff;  /* Bright blue for title */
            }
            .description {
                font-size: 20px;  /* Larger description font */
                text-align: center;  /* Centered description */
                margin-bottom: 20px;  /* Space below description */
                color: #555555;  /* Medium gray for description */
            }
            .footer {
                text-align: center;  /* Center footer text */
                margin-top: 20px;  /* Space above footer */
                color: #888888;  /* Light gray for footer text */
            }
        """,
        examples=[
            ["How are Daenerys and Jon Snow related?"],
            ["What is the fate of Bran Stark?"],
            ["Tell me about the Iron Throne."],
        ],
        share=True,
    )

    interface.launch()

if __name__ == "__main__":
    main()