nicolasmery commited on
Commit
3c95863
·
verified ·
1 Parent(s): 6f4076d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -15
app.py CHANGED
@@ -30,20 +30,7 @@ def embed(text):
30
  outputs = steelbert_model(**inputs, output_hidden_states=True)
31
  return outputs.hidden_states[-1][:,0,:].cpu().numpy()[0]
32
 
33
- # --- 3. Base documentaire (exemple, à remplacer par tes documents techniques) ---
34
- docs = {
35
- "doc1": "L’acier X42 a une résistance à la traction de 415 MPa.",
36
- "doc2": "L’acier inoxydable 304 est résistant à la corrosion et à l’oxydation."
37
- }
38
- doc_embeddings = {k: embed(v) for k,v in docs.items()}
39
-
40
- def search_best_doc(question):
41
- q_emb = embed(question)
42
- def cosine(a,b): return np.dot(a,b)/(np.linalg.norm(a)*np.linalg.norm(b))
43
- best_doc = max(docs, key=lambda k: cosine(q_emb, doc_embeddings[k]))
44
- return docs[best_doc]
45
-
46
- # --- 4. Fonction de réponse avec Mistral 7B Instruct ---
47
  def respond(
48
  message,
49
  history: list[dict[str, str]],
@@ -80,7 +67,7 @@ def respond(
80
  response += token
81
  yield response
82
 
83
- # --- 5. Interface Gradio ---
84
  chatbot = gr.ChatInterface(
85
  respond,
86
  type="messages",
 
30
  outputs = steelbert_model(**inputs, output_hidden_states=True)
31
  return outputs.hidden_states[-1][:,0,:].cpu().numpy()[0]
32
 
33
+ # --- 3. Fonction de réponse avec Mistral 7B Instruct ---
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  def respond(
35
  message,
36
  history: list[dict[str, str]],
 
67
  response += token
68
  yield response
69
 
70
+ # --- 4. Interface Gradio ---
71
  chatbot = gr.ChatInterface(
72
  respond,
73
  type="messages",