Futuresony commited on
Commit
2137129
·
verified ·
1 Parent(s): a21d70a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -3,30 +3,31 @@ from huggingface_hub import InferenceClient
3
 
4
  client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
5
 
6
- # Store conversation history
7
- def format_alpaca_prompt(history, user_input, system_prompt):
8
- """Formats input in Alpaca/LLaMA style with conversation history"""
9
- formatted_history = "\n".join([f"User: {h[0]}\nAssistant: {h[1]}" for h in history])
10
- prompt = f"""{system_prompt}\n{formatted_history}\nUser: {user_input}\nAssistant:"""
 
 
 
 
11
  return prompt
12
 
13
  def respond(message, history, system_message, max_tokens, temperature, top_p):
14
- formatted_prompt = format_alpaca_prompt(history, message, system_message)
15
-
16
  response = client.text_generation(
17
  formatted_prompt,
18
  max_new_tokens=max_tokens,
19
  temperature=temperature,
20
  top_p=top_p,
21
  )
 
 
 
22
 
23
- # Extract only the response
24
- cleaned_response = response.strip().split("Assistant:")[-1].strip()
25
-
26
- # Update history
27
- history.append((message, cleaned_response))
28
-
29
- return cleaned_response # Output only the answer
30
 
31
  demo = gr.ChatInterface(
32
  respond,
@@ -38,5 +39,6 @@ demo = gr.ChatInterface(
38
  ],
39
  )
40
 
41
- if __name__ == "__main__":
42
- demo.launch()
 
 
3
 
4
  client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
5
 
6
+ def format_alpaca_prompt(user_input, system_prompt):
7
+ """Formats input in Alpaca/LLaMA style"""
8
+ prompt = f"""{system_prompt}
9
+
10
+ ### Instruction:
11
+ {user_input}
12
+
13
+ ### Response:
14
+ """
15
  return prompt
16
 
17
  def respond(message, history, system_message, max_tokens, temperature, top_p):
18
+ formatted_prompt = format_alpaca_prompt(message, system_message)
19
+
20
  response = client.text_generation(
21
  formatted_prompt,
22
  max_new_tokens=max_tokens,
23
  temperature=temperature,
24
  top_p=top_p,
25
  )
26
+
27
+ # ✅ Extract only the response
28
+ cleaned_response = response.split("### Response:")[-1].strip()
29
 
30
+ yield cleaned_response # Output only the answer
 
 
 
 
 
 
31
 
32
  demo = gr.ChatInterface(
33
  respond,
 
39
  ],
40
  )
41
 
42
+ if
43
+ __name__ == "__main__":
44
+ demo.launch()