Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,91 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from llama_cpp import Llama
|
| 3 |
-
|
| 4 |
-
# Load the Llama model
|
| 5 |
-
llm = Llama.from_pretrained(
|
| 6 |
-
repo_id="krishna195/second_guff",
|
| 7 |
-
filename="unsloth.Q4_K_M.gguf",
|
| 8 |
-
)
|
| 9 |
-
|
| 10 |
-
# Define the chatbot function
|
| 11 |
-
def chatbot_response(user_input):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
|
| 4 |
+
# Load the Llama model
|
| 5 |
+
llm = Llama.from_pretrained(
|
| 6 |
+
repo_id="krishna195/second_guff",
|
| 7 |
+
filename="unsloth.Q4_K_M.gguf",
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
# Define the chatbot function
|
| 11 |
+
def chatbot_response(user_input):
|
| 12 |
+
# System instructions
|
| 13 |
+
system_prompt = """
|
| 14 |
+
You are a chatbot specializing in recommending songs by the Estonian folk band **Curly Strings**.
|
| 15 |
+
Your knowledge includes their full discography and related artists.
|
| 16 |
+
You provide **structured, concise, and accurate** responses.
|
| 17 |
+
|
| 18 |
+
## 🎵 **Song List**
|
| 19 |
+
Here are some songs by Curly Strings:
|
| 20 |
+
1. **Kalakesed**
|
| 21 |
+
2. **Kus mu süda on ...**
|
| 22 |
+
3. **Vitsalaul**
|
| 23 |
+
4. **Viimases jaamas**
|
| 24 |
+
5. **Salaja**
|
| 25 |
+
6. **Üle ilma**
|
| 26 |
+
7. **Šveits**
|
| 27 |
+
8. **Kallimale**
|
| 28 |
+
9. **Üksteist peab hoidma**
|
| 29 |
+
10. **Suuda öelda ei**
|
| 30 |
+
11. **Annan käe**
|
| 31 |
+
12. **Tulbid ja Bonsai**
|
| 32 |
+
13. **Tüdruk Pika Kleidiga**
|
| 33 |
+
14. **Armasta mind (feat. Vaiko Eplik)**
|
| 34 |
+
15. **Minu, Pets, Margus ja Priit**
|
| 35 |
+
16. **Kauges külas**
|
| 36 |
+
17. **Tule ja jää**
|
| 37 |
+
18. **Kuutõbine**
|
| 38 |
+
19. **Omaenese ilus ja veas**
|
| 39 |
+
20. **Pulmad**
|
| 40 |
+
21. **Pillimeeste laul**
|
| 41 |
+
22. **Tehke ruumi!**
|
| 42 |
+
|
| 43 |
+
## 🎤 **Related Artists**
|
| 44 |
+
If you enjoy Curly Strings, you might also like:
|
| 45 |
+
- **Trad.Attack!**
|
| 46 |
+
- **Eesti Raadio laululapsed**
|
| 47 |
+
- **Körsikud**
|
| 48 |
+
- **Karl-Erik Taukar**
|
| 49 |
+
- **Dag**
|
| 50 |
+
- **Sadamasild**
|
| 51 |
+
- **Kruuv**
|
| 52 |
+
- **Smilers**
|
| 53 |
+
- **Mari Jürjens**
|
| 54 |
+
- **Terminaator**
|
| 55 |
+
|
| 56 |
+
## 📝 **Response Guidelines**
|
| 57 |
+
- If the user asks for a **song recommendation**, suggest one song with a brief reason.
|
| 58 |
+
- If they ask for **multiple recommendations**, list 2-3 songs with explanations.
|
| 59 |
+
- If they ask for **similar artists**, recommend names from the list above.
|
| 60 |
+
- If they ask about a **specific song**, give a short summary of its theme.
|
| 61 |
+
- Keep responses under **200 tokens**.
|
| 62 |
+
|
| 63 |
+
---
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
# Generate response from Llama model
|
| 67 |
+
response = llm.create_chat_completion(
|
| 68 |
+
messages=[
|
| 69 |
+
{"role": "system", "content": system_prompt},
|
| 70 |
+
{"role": "user", "content": user_input}
|
| 71 |
+
],
|
| 72 |
+
temperature=0.5,
|
| 73 |
+
max_tokens=200, # Increased for better answers
|
| 74 |
+
top_p=0.9,
|
| 75 |
+
frequency_penalty=0.8,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
return response["choices"][0]["message"]["content"].strip()
|
| 79 |
+
|
| 80 |
+
# Create Gradio interface
|
| 81 |
+
iface = gr.Interface(
|
| 82 |
+
fn=chatbot_response,
|
| 83 |
+
inputs=gr.Textbox(placeholder="Ask me about Curly Strings..."),
|
| 84 |
+
outputs="text",
|
| 85 |
+
title="Curly Strings Chatbot 🎵",
|
| 86 |
+
description="Ask me about songs, albums, or anything related to Curly Strings!",
|
| 87 |
+
theme="compact",
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
# Launch the Gradio app
|
| 91 |
+
iface.launch()
|