Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,28 +3,30 @@ from huggingface_hub import InferenceClient
|
|
3 |
|
4 |
client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
5 |
|
6 |
-
# Store
|
7 |
-
def format_alpaca_prompt(
|
8 |
-
"""Formats input in Alpaca/LLaMA style with history"""
|
9 |
-
|
10 |
-
prompt = f"""{system_prompt}\n{
|
11 |
return prompt
|
12 |
|
13 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
14 |
-
formatted_prompt = format_alpaca_prompt(
|
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 |
-
#
|
24 |
cleaned_response = response.strip()
|
25 |
|
26 |
-
|
27 |
-
|
|
|
|
|
28 |
|
29 |
demo = gr.ChatInterface(
|
30 |
respond,
|
|
|
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()
|
25 |
|
26 |
+
# Update history
|
27 |
+
history.append((message, cleaned_response))
|
28 |
+
|
29 |
+
yield cleaned_response # Output only the answer
|
30 |
|
31 |
demo = gr.ChatInterface(
|
32 |
respond,
|