Futuresony commited on
Commit
52eb24f
·
verified ·
1 Parent(s): acf9986

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -23
app.py CHANGED
@@ -1,30 +1,19 @@
1
- import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
5
-
6
  def respond(message, history, max_tokens, temperature, top_p):
7
- """Generates only a short, direct response without extra text."""
 
 
 
 
 
8
  response = client.text_generation(
9
  message.strip(),
10
  max_new_tokens=max_tokens,
11
  temperature=temperature,
12
  top_p=top_p,
13
- )
14
-
15
- # Remove "I am... ", "What do you do?", "Can you help me...?", etc.
16
- response = response.strip().split("\n")[0] # Keep only the first line
17
-
18
- yield response
19
-
20
- demo = gr.ChatInterface(
21
- respond,
22
- additional_inputs=[
23
- gr.Slider(minimum=1, maximum=250, value=128, step=1, label="Max new tokens"),
24
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
25
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
26
- ],
27
- )
28
 
29
- if __name__ == "__main__":
30
- demo.launch()
 
 
 
 
 
 
1
  def respond(message, history, max_tokens, temperature, top_p):
2
+ """Generate a response while preventing unnecessary repetition."""
3
+
4
+ # Ensure the message isn't directly repeated
5
+ if history and message.strip() == history[-1][0].strip():
6
+ return "Tafadhali uliza swali tofauti." # Prevent direct repetition
7
+
8
  response = client.text_generation(
9
  message.strip(),
10
  max_new_tokens=max_tokens,
11
  temperature=temperature,
12
  top_p=top_p,
13
+ ).strip()
14
+
15
+ # Remove repeated input
16
+ if response.lower() == message.lower():
17
+ response = "Samahani, naweza kusaidia vipi?"
 
 
 
 
 
 
 
 
 
 
18
 
19
+ return response