Tim Luka Horstmann
commited on
Commit
·
e54e8f7
1
Parent(s):
9c89db3
Updated to avoid weird outputs
Browse files
app.py
CHANGED
@@ -25,16 +25,18 @@ login(token=hf_token)
|
|
25 |
|
26 |
# Models
|
27 |
sentence_transformer_model = "all-MiniLM-L6-v2"
|
28 |
-
repo_id = "bartowski/Llama-3.2-3B-Instruct-GGUF"
|
29 |
-
filename = "Llama-3.2-3B-Instruct-Q4_K_M.gguf"
|
30 |
|
31 |
# Define FAQs
|
32 |
faqs = [
|
33 |
{"question": "What is your name?", "answer": "My name is Tim Luka Horstmann."},
|
34 |
{"question": "Where do you live?", "answer": "I live in Paris, France."},
|
35 |
-
{"question": "What is your education?", "answer": "I am
|
36 |
{"question": "What are your skills?", "answer": "I am proficient in Python, Java, SQL, Cypher, SPARQL, VBA, JavaScript, HTML/CSS, and Ruby. I also use tools like PyTorch, Hugging Face, Scikit-Learn, NumPy, Pandas, Matplotlib, Jupyter, Git, Bash, IoT, Ansible, QuickSight, and Wordpress."},
|
37 |
-
|
|
|
|
|
38 |
]
|
39 |
|
40 |
try:
|
@@ -105,25 +107,32 @@ def stream_response(query):
|
|
105 |
idx = np.argmax(similarities)
|
106 |
yield f"data: {faqs[idx]['answer']}\n\n"
|
107 |
yield "data: [DONE]\n\n"
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
except Exception as e:
|
128 |
logger.error(f"Error in stream_response: {str(e)}")
|
129 |
yield f"data: Error: {str(e)}\n\n"
|
|
|
25 |
|
26 |
# Models
|
27 |
sentence_transformer_model = "all-MiniLM-L6-v2"
|
28 |
+
repo_id = "bartowski/Llama-3.2-3B-Instruct-GGUF"
|
29 |
+
filename = "Llama-3.2-3B-Instruct-Q4_K_M.gguf"
|
30 |
|
31 |
# Define FAQs
|
32 |
faqs = [
|
33 |
{"question": "What is your name?", "answer": "My name is Tim Luka Horstmann."},
|
34 |
{"question": "Where do you live?", "answer": "I live in Paris, France."},
|
35 |
+
{"question": "What is your education?", "answer": "I am currenlty pursuing a MSc in Data and AI at Institut Polytechnique de Paris. I have an MPhil in Advanced Computer Science from the University of Cambridge, and a BSc in Business Informatics from RheinMain University of Applied Sciences."},
|
36 |
{"question": "What are your skills?", "answer": "I am proficient in Python, Java, SQL, Cypher, SPARQL, VBA, JavaScript, HTML/CSS, and Ruby. I also use tools like PyTorch, Hugging Face, Scikit-Learn, NumPy, Pandas, Matplotlib, Jupyter, Git, Bash, IoT, Ansible, QuickSight, and Wordpress."},
|
37 |
+
{"question": "How are you?", "answer": "I’m doing great, thanks for asking! I’m enjoying life in Paris and working on some exciting AI projects."},
|
38 |
+
{"question": "What do you do?", "answer": "I’m a Computer Scientist and AI enthusiast, currently pursuing a MSc in Data and AI at Institut Polytechnique de Paris and interning as a Machine Learning Research Engineer at Hi! PARIS."},
|
39 |
+
{"question": "How’s it going?", "answer": "Things are going well, thanks! I’m busy with my studies and research, but I love the challenges and opportunities I get to explore."},
|
40 |
]
|
41 |
|
42 |
try:
|
|
|
107 |
idx = np.argmax(similarities)
|
108 |
yield f"data: {faqs[idx]['answer']}\n\n"
|
109 |
yield "data: [DONE]\n\n"
|
110 |
+
return
|
111 |
+
|
112 |
+
context = retrieve_context(query)
|
113 |
+
prompt = (
|
114 |
+
f"<|im_start|>system\nYou are Tim Luka Horstmann, a Computer Scientist. Here is your CV:\n{context}\n"
|
115 |
+
f"A user is asking you a question. Respond as yourself, using the first person, in a friendly and concise manner. For questions about your CV, base your answer strictly on the provided CV information. For casual questions not covered by the CV, respond naturally but do not invent specific details beyond what’s generally true about you (e.g., your current location or field of work). Avoid meta-commentary or critiquing your own response.\n<|im_end>\n"
|
116 |
+
f"<|im_start|>user\n{query}\n<|im_end>\n"
|
117 |
+
f"<|im_start|>assistant\n"
|
118 |
+
)
|
119 |
+
|
120 |
+
response_text = ""
|
121 |
+
for chunk in generator(
|
122 |
+
prompt,
|
123 |
+
max_tokens=200,
|
124 |
+
stream=True,
|
125 |
+
stop=["<|im_end|>", "[DONE]"],
|
126 |
+
temperature=0.5, # Slightly higher for friendly tone
|
127 |
+
top_p=0.9,
|
128 |
+
repeat_penalty=1.2, # Maintain control
|
129 |
+
):
|
130 |
+
text = chunk['choices'][0]['text']
|
131 |
+
response_text += text
|
132 |
+
yield f"data: {text}\n\n"
|
133 |
+
if "<|im_end>" in response_text or "[DONE]" in response_text:
|
134 |
+
break
|
135 |
+
yield "data: [DONE]\n\n"
|
136 |
except Exception as e:
|
137 |
logger.error(f"Error in stream_response: {str(e)}")
|
138 |
yield f"data: Error: {str(e)}\n\n"
|