Yadukrishnan commited on
Commit
a6ea74a
·
verified ·
1 Parent(s): 8c7d247

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -51
app.py CHANGED
@@ -1,4 +1,9 @@
1
  import gradio as gr
 
 
 
 
 
2
  from huggingface_hub import InferenceClient
3
 
4
  """
@@ -6,58 +11,60 @@ For more information on `huggingface_hub` Inference API support, please check th
6
  """
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
 
9
 
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
-
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
- demo = gr.ChatInterface(
46
- respond,
47
- additional_inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
- gr.Slider(
52
- minimum=0.1,
53
- maximum=1.0,
54
- value=0.95,
55
- step=0.05,
56
- label="Top-p (nucleus sampling)",
57
- ),
58
- ],
59
- )
60
 
 
61
 
62
  if __name__ == "__main__":
63
- demo.launch()
 
1
  import gradio as gr
2
+
3
+ from model_loader import load_model
4
+ from retriever import setup_retriever
5
+ from llm_chain import setup_llm_chain
6
+ from utils import generate_response
7
  from huggingface_hub import InferenceClient
8
 
9
  """
 
11
  """
12
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
13
 
14
+ # Load necessary components
15
+ retriever = setup_retriever()
16
+ llm_chain = setup_llm_chain()
17
 
18
+ def main():
19
+ interface = gr.Interface
20
+ (
21
+ fn=lambda question: generate_response(question, retriever, llm_chain),
22
+ inputs=gr.Textbox(placeholder="Ask your question...", label="Your Question", lines=2),
23
+ outputs=gr.Textbox(label="Bloodraven's Response", lines=5, interactive=False),
24
+ title="Bloodraven Chatbot",
25
+ description="Ask any question and receive cryptic, prophetic answers from the Bloodraven from A Song of Ice and Fire.",
26
+ css="""
27
+ .gradio-container {
28
+ font-family: 'Arial', sans-serif; /* Simple, clear font */
29
+ background-color: #f9f9f9; /* Light gray background */
30
+ color: #333333; /* Dark gray text for contrast */
31
+ }
32
+ .input_textbox, .output_textbox {
33
+ border-radius: 5px; /* Rounded corners */
34
+ border: 2px solid #007bff; /* Bright blue border */
35
+ background-color: #ffffff; /* White background for input/output boxes */
36
+ color: #333333; /* Dark gray text for visibility */
37
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); /* Subtle shadow */
38
+ }
39
+ .input_textbox:focus, .output_textbox:focus {
40
+ border-color: #ff4500; /* Bright orange-red border on focus */
41
+ }
42
+ .title {
43
+ font-size: 36px; /* Larger title */
44
+ font-weight: bold; /* Bold title */
45
+ text-align: center; /* Centered title */
46
+ color: #007bff; /* Bright blue for title */
47
+ }
48
+ .description {
49
+ font-size: 20px; /* Larger description font */
50
+ text-align: center; /* Centered description */
51
+ margin-bottom: 20px; /* Space below description */
52
+ color: #555555; /* Medium gray for description */
53
+ }
54
+ .footer {
55
+ text-align: center; /* Center footer text */
56
+ margin-top: 20px; /* Space above footer */
57
+ color: #888888; /* Light gray for footer text */
58
+ }
59
+ """,
60
+ examples=[
61
+ ["How are Daenerys and Jon Snow related?"],
62
+ ["What is the fate of Bran Stark?"],
63
+ ["Tell me about the Iron Throne."],
64
+ ],
65
+ )
 
 
66
 
67
+ interface.launch()
68
 
69
  if __name__ == "__main__":
70
+ main()