Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,44 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
"""
|
| 5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
"""
|
| 7 |
client = InferenceClient("Futuresony/future_ai_12_10_2024.gguf")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
system_message,
|
| 14 |
-
max_tokens,
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
| 17 |
-
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
| 19 |
-
|
| 20 |
-
for user_message, assistant_message in history:
|
| 21 |
-
if user_message:
|
| 22 |
-
messages.append({"role": "user", "content": user_message})
|
| 23 |
-
if assistant_message:
|
| 24 |
-
messages.append({"role": "assistant", "content": assistant_message})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
response = client.chat_completion(
|
| 29 |
-
model='Futuresony/future_ai_12_10_2024.gguf',
|
| 30 |
-
messages=messages,
|
| 31 |
-
max_tokens=max_tokens,
|
| 32 |
temperature=temperature,
|
| 33 |
top_p=top_p,
|
| 34 |
-
stream=False
|
| 35 |
)
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
"""
|
| 41 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 42 |
-
"""
|
| 43 |
demo = gr.ChatInterface(
|
| 44 |
respond,
|
| 45 |
additional_inputs=[
|
| 46 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 47 |
-
gr.Slider(minimum=1, maximum=
|
| 48 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 49 |
-
gr.Slider(
|
| 50 |
-
minimum=0.1,
|
| 51 |
-
maximum=1.0,
|
| 52 |
-
value=0.95,
|
| 53 |
-
step=0.05,
|
| 54 |
-
label="Top-p (nucleus sampling)",
|
| 55 |
-
),
|
| 56 |
],
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
if __name__ == "__main__":
|
| 61 |
demo.launch()
|
|
|
|
| 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 format_alpaca_prompt(history, user_input, system_prompt):
|
| 7 |
+
"""Formats input in Alpaca/LLaMA style with history"""
|
| 8 |
+
history_prompt = "\n".join([f"User: {h[0]}\nAssistant: {h[1]}" for h in history])
|
| 9 |
+
prompt = f"""{system_prompt}
|
| 10 |
+
|
| 11 |
+
{history_prompt}
|
| 12 |
+
|
| 13 |
+
User: {user_input}
|
| 14 |
+
Assistant:
|
| 15 |
+
"""
|
| 16 |
+
return prompt
|
| 17 |
+
|
| 18 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
| 19 |
+
formatted_prompt = format_alpaca_prompt(history, message, system_message)
|
| 20 |
|
| 21 |
+
response = client.text_generation(
|
| 22 |
+
formatted_prompt,
|
| 23 |
+
max_new_tokens=max_tokens,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
temperature=temperature,
|
| 25 |
top_p=top_p,
|
|
|
|
| 26 |
)
|
| 27 |
|
| 28 |
+
# Extract only the response
|
| 29 |
+
cleaned_response = response.split("Assistant:")[-1].strip()
|
| 30 |
+
|
| 31 |
+
yield cleaned_response # Output only the answer
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
demo = gr.ChatInterface(
|
| 34 |
respond,
|
| 35 |
additional_inputs=[
|
| 36 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 37 |
+
gr.Slider(minimum=1, maximum=250, value=128, step=1, label="Max new tokens"),
|
| 38 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 39 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
],
|
| 41 |
)
|
| 42 |
|
|
|
|
| 43 |
if __name__ == "__main__":
|
| 44 |
demo.launch()
|