Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,16 +23,30 @@ def get_yt_links(contexts):
|
|
| 23 |
yt_htmls.append(html.format(link, start))
|
| 24 |
return yt_htmls
|
| 25 |
|
| 26 |
-
def resp2msg(resp):
|
| 27 |
req = resp['input']
|
| 28 |
ans = resp['answer']
|
| 29 |
-
return req + '\n' + ans
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def process_input(text):
|
| 32 |
response = retrieval_chain.invoke({"input": text})
|
| 33 |
#bot.send_message(user_id, resp2msg(response))
|
| 34 |
youtube_links = get_yt_links(response['context'])
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
giga = os.getenv('GIGA')
|
| 38 |
#token = os.getenv('BOT')
|
|
@@ -73,13 +87,14 @@ with gr.Blocks() as demo:
|
|
| 73 |
text_input = gr.Textbox(label="Введите запрос")
|
| 74 |
submit_btn = gr.Button("Отправить запрос")
|
| 75 |
text_output = gr.Textbox(label="Ответ", interactive=False)
|
|
|
|
| 76 |
|
| 77 |
with gr.Column():
|
| 78 |
youtube_video1 = gr.HTML()
|
| 79 |
youtube_video2 = gr.HTML()
|
| 80 |
youtube_video3 = gr.HTML()
|
| 81 |
|
| 82 |
-
submit_btn.click(process_input, text_input, [text_output, youtube_video1, youtube_video2, youtube_video3])
|
| 83 |
|
| 84 |
|
| 85 |
demo.launch()
|
|
|
|
| 23 |
yt_htmls.append(html.format(link, start))
|
| 24 |
return yt_htmls
|
| 25 |
|
| 26 |
+
'''def resp2msg(resp):
|
| 27 |
req = resp['input']
|
| 28 |
ans = resp['answer']
|
| 29 |
+
return req + '\n' + ans'''
|
| 30 |
+
|
| 31 |
+
def get_context(contexts):
|
| 32 |
+
txt_context = '''
|
| 33 |
+
Фрагмент 1: {}
|
| 34 |
+
Фрагмент 2: {}
|
| 35 |
+
Фрагмент 3: {}
|
| 36 |
+
'''.format(
|
| 37 |
+
contexts[0].page_content,
|
| 38 |
+
contexts[1].page_content,
|
| 39 |
+
contexts[2].page_content,
|
| 40 |
+
)
|
| 41 |
+
return txt_context
|
| 42 |
+
|
| 43 |
|
| 44 |
def process_input(text):
|
| 45 |
response = retrieval_chain.invoke({"input": text})
|
| 46 |
#bot.send_message(user_id, resp2msg(response))
|
| 47 |
youtube_links = get_yt_links(response['context'])
|
| 48 |
+
context = get_context(response['context'])
|
| 49 |
+
return response['answer'], context, youtube_links[0], youtube_links[1], youtube_links[2]
|
| 50 |
|
| 51 |
giga = os.getenv('GIGA')
|
| 52 |
#token = os.getenv('BOT')
|
|
|
|
| 87 |
text_input = gr.Textbox(label="Введите запрос")
|
| 88 |
submit_btn = gr.Button("Отправить запрос")
|
| 89 |
text_output = gr.Textbox(label="Ответ", interactive=False)
|
| 90 |
+
text_context = gr.Textbox(label="Контекст", interactive=False)
|
| 91 |
|
| 92 |
with gr.Column():
|
| 93 |
youtube_video1 = gr.HTML()
|
| 94 |
youtube_video2 = gr.HTML()
|
| 95 |
youtube_video3 = gr.HTML()
|
| 96 |
|
| 97 |
+
submit_btn.click(process_input, text_input, [text_output, text_context, youtube_video1, youtube_video2, youtube_video3])
|
| 98 |
|
| 99 |
|
| 100 |
demo.launch()
|