Threatthriver commited on
Commit
6717fb6
1 Parent(s): fb5b02d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -51
app.py CHANGED
@@ -1,6 +1,6 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
- import random
4
 
5
  API_URL = "https://api-inference.huggingface.co/models/"
6
 
@@ -16,24 +16,19 @@ def format_prompt(message, history):
16
  prompt += f"[INST] {message} [/INST]"
17
  return prompt
18
 
19
- def generate(prompt, history, temperature=0.9, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
20
  """Generate a response using the text generation model."""
21
- # Ensure temperature is not too low
22
- temperature = max(float(temperature), 1e-2)
23
- top_p = float(top_p)
24
-
25
  # Check if the prompt is asking who created the bot
26
  if "who created you" in prompt.lower():
27
  return "I was created by Aniket Kumar and many more."
28
 
29
  # Set up parameters for text generation
30
  generate_kwargs = dict(
31
- temperature=temperature,
32
- max_new_tokens=max_new_tokens,
33
- top_p=top_p,
34
- repetition_penalty=repetition_penalty,
35
  do_sample=True,
36
- seed=random.randint(0, 10**7),
37
  )
38
 
39
  # Format the prompt
@@ -47,47 +42,19 @@ def generate(prompt, history, temperature=0.9, max_new_tokens=512, top_p=0.95, r
47
  yield output
48
  return output
49
 
 
 
 
 
 
 
 
 
 
 
 
50
  def create_interface():
51
  """Create the Gradio interface."""
52
- additional_inputs=[
53
- gr.Slider(
54
- label="Temperature",
55
- value=0.9,
56
- minimum=0.0,
57
- maximum=1.0,
58
- step=0.05,
59
- interactive=True,
60
- info="Higher values produce more diverse outputs",
61
- ),
62
- gr.Slider(
63
- label="Max new tokens",
64
- value=512,
65
- minimum=64,
66
- maximum=1024,
67
- step=64,
68
- interactive=True,
69
- info="The maximum numbers of new tokens",
70
- ),
71
- gr.Slider(
72
- label="Top-p (nucleus sampling)",
73
- value=0.90,
74
- minimum=0.0,
75
- maximum=1,
76
- step=0.05,
77
- interactive=True,
78
- info="Higher values sample more low-probability tokens",
79
- ),
80
- gr.Slider(
81
- label="Repetition penalty",
82
- value=1.2,
83
- minimum=1.0,
84
- maximum=2.0,
85
- step=0.05,
86
- interactive=True,
87
- info="Penalize repeated tokens",
88
- )
89
- ]
90
-
91
  customCSS = """
92
  #component-7 { # this is the default element ID of the chat component
93
  height: 800px; # adjust the height as needed
@@ -98,7 +65,7 @@ def create_interface():
98
  with gr.Blocks(css=customCSS) as demo:
99
  gr.ChatInterface(
100
  generate,
101
- additional_inputs=additional_inputs,
102
  )
103
 
104
  demo.queue().launch(debug=True)
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
+ from datetime import datetime
4
 
5
  API_URL = "https://api-inference.huggingface.co/models/"
6
 
 
16
  prompt += f"[INST] {message} [/INST]"
17
  return prompt
18
 
19
+ def generate(prompt, history):
20
  """Generate a response using the text generation model."""
 
 
 
 
21
  # Check if the prompt is asking who created the bot
22
  if "who created you" in prompt.lower():
23
  return "I was created by Aniket Kumar and many more."
24
 
25
  # Set up parameters for text generation
26
  generate_kwargs = dict(
27
+ temperature=0.9,
28
+ max_new_tokens=512,
29
+ top_p=0.95,
30
+ repetition_penalty=1.0,
31
  do_sample=True,
 
32
  )
33
 
34
  # Format the prompt
 
42
  yield output
43
  return output
44
 
45
+ def greet_user():
46
+ """Greet the user based on the time of day."""
47
+ current_hour = datetime.now().hour
48
+
49
+ if current_hour < 12:
50
+ return "Good morning! How can I assist you today?"
51
+ elif 12 <= current_hour < 18:
52
+ return "Good afternoon! How can I assist you today?"
53
+ else:
54
+ return "Good evening! How can I assist you today?"
55
+
56
  def create_interface():
57
  """Create the Gradio interface."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  customCSS = """
59
  #component-7 { # this is the default element ID of the chat component
60
  height: 800px; # adjust the height as needed
 
65
  with gr.Blocks(css=customCSS) as demo:
66
  gr.ChatInterface(
67
  generate,
68
+ initial_message=greet_user(), # Add the greeting feature here
69
  )
70
 
71
  demo.queue().launch(debug=True)