AndreaAlessandrelli4 commited on
Commit
99a86e4
·
verified ·
1 Parent(s): cd86962

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -29
app.py CHANGED
@@ -1,9 +1,7 @@
1
  import os
2
  from threading import Thread
3
  from typing import Iterator
4
- from haystack import Document
5
- from haystack import Pipeline
6
- from haystack.components.embedders import SentenceTransformersTextEmbedder
7
  import gradio as gr
8
  import spaces
9
  import torch
@@ -29,39 +27,20 @@ if torch.cuda.is_available():
29
 
30
 
31
 
32
- key='4vNfIDO8PmFwCloxA40y2b4PSHm62vmcuPoM'
33
- url = "https://mmchpi0yssanukk5t3ofta.c0.europe-west3.gcp.weaviate.cloud"
34
  # instanziamento client weaviate
35
- client = weaviate.Client(
36
- url = url,
37
- auth_client_secret=weaviate.auth.AuthApiKey(api_key=key),
38
- #embedded_options=weaviate.embedded.EmbeddedOptions(),
39
- )
40
 
41
 
42
 
43
 
44
 
45
- def vettorizz_query(query):
46
- vector_query=query_pipeline1.run({ "text_embedder": {"text": query},
47
- })['text_embedder']['embedding']
48
- return query, vector_query
49
 
50
- def richiamo_materiali(query, alpha, N_items):
51
- text_query, vett_query = vettorizz_query(query)
52
- try:
53
- materiali = client.query.get("Default", ["content"]).with_hybrid(
54
- query=text_query,
55
- vector=vett_query,
56
- alpha=alpha,
57
- fusion_type=HybridFusion.RELATIVE_SCORE,
58
- ).with_additional(["score"]).with_limit(N_items).do()
59
-
60
- mat = [{'score':i['_additional']['score'],'content':i['content']} for i in materiali['data']['Get']['Default']]
61
- except:
62
- mat =[{'score':0, 'content':'NESSUN MATERIALE FORNITO'}]
63
-
64
- return mat
65
 
66
 
67
 
 
1
  import os
2
  from threading import Thread
3
  from typing import Iterator
4
+
 
 
5
  import gradio as gr
6
  import spaces
7
  import torch
 
27
 
28
 
29
 
30
+ #key='4vNfIDO8PmFwCloxA40y2b4PSHm62vmcuPoM'
31
+ #url = "https://mmchpi0yssanukk5t3ofta.c0.europe-west3.gcp.weaviate.cloud"
32
  # instanziamento client weaviate
33
+ #client = weaviate.Client(
34
+ # url = url,
35
+ # auth_client_secret=weaviate.auth.AuthApiKey(api_key=key),
36
+ # #embedded_options=weaviate.embedded.EmbeddedOptions(),
37
+ #)
38
 
39
 
40
 
41
 
42
 
 
 
 
 
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
 
46