TorTorosov commited on
Commit
d94ca47
·
verified ·
1 Parent(s): 321b486

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -63
app.py CHANGED
@@ -1,67 +1,15 @@
1
  import gradio as gr
2
- import logging
3
 
4
- logging.getLogger("httpx").setLevel(logging.ERROR)
 
5
 
6
- def show_image(img):
7
- global query
8
- query = ""
9
-
10
- # Проверка, что изображение не None
11
- if img is None:
12
- return None, gr.update(value="No image provided") # Возвращаем None как изображение и сообщение
13
-
14
- # Обработка изображения
15
- data_batch[0].append(preprocess(img))
16
- embeds = embed(data_batch[0])
17
- res = collection.search(embeds, anns_field='image_embedding', param={'nprobe': 128}, limit=TOP_K, output_fields=['filepath'])
18
-
19
- for hits_i, hits in enumerate(res):
20
- for hit_i, hit in enumerate(hits):
21
- img_path = hit.entity.get('filepath')
22
- _ph_ = str(img_path)
23
- ph_ = _ph_[8:len(_ph_)]
24
- x = ph_.find("\\")
25
- query = ph_[:x] if ph_[:x] != "NoName" else ""
26
-
27
- return img_path, gr.update(value=query)
28
 
29
- def display_results(_query):
30
- global query
31
- if _query: # Проверка, что запрос не пустой
32
- query = _query
33
- else:
34
- return "Please enter a search query or upload an image."
35
-
36
- query_embeddings = ef([query])
37
- dense_results = dense_search(col, query_embeddings["dense"][0])
38
- sparse_results = sparse_search(col, query_embeddings["sparse"]._getrow(0))
39
- hybrid_results = hybrid_search(
40
- col,
41
- query_embeddings["dense"][0],
42
- query_embeddings["sparse"]._getrow(0),
43
- sparse_weight=0.7,
44
- dense_weight=1.0,
45
- )
46
-
47
- formatted_results = doc_text_formatting(ef, query, hybrid_results)
48
- results_md = f'<span style="color: {color[0]}">{query}</span>\n'
49
- for result in formatted_results:
50
- results_md += f"\n{result}"
51
- return results_md
52
-
53
- # Интерфейс Gradio
54
- with gr.Blocks(css=".progress-text { display: none !important; }") as demo:
55
- with gr.Row():
56
- image_input = gr.Image(label="Input Image Component", type="pil", width=320, height=320)
57
- image_output = gr.Image(label="Output Image Component", width=320, height=320)
58
-
59
- with gr.Column():
60
- field_query = gr.Textbox(label="Search Query")
61
- result_display = gr.Markdown()
62
- submit_button = gr.Button("Submit")
63
-
64
- image_input.change(fn=show_image, inputs=image_input, outputs=[image_output, field_query])
65
- submit_button.click(fn=display_results, inputs=field_query, outputs=result_display)
66
-
67
- demo.launch(share=False)
 
1
  import gradio as gr
 
2
 
3
+ def greet(name):
4
+ return f"Привет, {name}! Это динамический результат."
5
 
6
+ demo = gr.Interface(
7
+ fn=greet,
8
+ inputs="text",
9
+ outputs="text",
10
+ title="Приветствие от Gradio",
11
+ description="Введи своё имя, чтобы получить приветствие!"
12
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ if __name__ == "__main__":
15
+ demo.launch()