Spaces:
Sleeping
Sleeping
QAway-to
commited on
Commit
·
a928dd2
1
Parent(s):
617a6b6
model change
Browse files- analyzer.py +3 -4
- app.py +25 -10
analyzer.py
CHANGED
|
@@ -43,10 +43,9 @@ def analyze_portfolio_streaming(text: str, client:OpenAI):
|
|
| 43 |
|
| 44 |
partial = ""
|
| 45 |
for chunk in response_llm:
|
| 46 |
-
delta
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
yield partial
|
| 50 |
|
| 51 |
except Exception as e:
|
| 52 |
yield f"❌ Ошибка при обработке: {e}"
|
|
|
|
| 43 |
|
| 44 |
partial = ""
|
| 45 |
for chunk in response_llm:
|
| 46 |
+
if (delta := chunk.choices[0].delta.content):
|
| 47 |
+
yield delta
|
| 48 |
+
|
|
|
|
| 49 |
|
| 50 |
except Exception as e:
|
| 51 |
yield f"❌ Ошибка при обработке: {e}"
|
app.py
CHANGED
|
@@ -68,8 +68,8 @@ def handle_chat_streaming(user_input):
|
|
| 68 |
partial += delta
|
| 69 |
yield partial
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
|
| 74 |
|
| 75 |
def compare_analyze(text1, text2):
|
|
@@ -80,29 +80,44 @@ def compare_analyze(text1, text2):
|
|
| 80 |
with gr.Blocks() as demo:
|
| 81 |
gr.Markdown("## 🧠 Анализ и сравнение инвестиционных портфелей Tradelink")
|
| 82 |
|
|
|
|
| 83 |
with gr.Tab("📊 Анализ"):
|
| 84 |
portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
|
| 85 |
-
analyze_button = gr.Button("🔍 Проанализировать")
|
| 86 |
output_box = gr.Textbox(label="📈 Результат анализа", lines=15)
|
|
|
|
|
|
|
|
|
|
| 87 |
analyze_button.click(
|
| 88 |
-
fn=
|
| 89 |
inputs=portfolio_input,
|
| 90 |
-
outputs=output_box
|
| 91 |
-
)
|
| 92 |
|
|
|
|
| 93 |
with gr.Tab("⚖️ Сравнение"):
|
| 94 |
compare_input_1 = gr.Textbox(label="Портфель 1", placeholder="ea856c1b-...")
|
| 95 |
compare_input_2 = gr.Textbox(label="Портфель 2", placeholder="d52f55cc-...")
|
| 96 |
-
compare_button = gr.Button("📊 Сравнить")
|
| 97 |
compare_output = gr.Textbox(label="📉 Результат сравнения", lines=20)
|
| 98 |
-
compare_button
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
with gr.Tab("💬 Диалог"):
|
| 101 |
chat_input = gr.Textbox(label="Ваш вопрос", placeholder="Что такое TradeLink Passport?")
|
| 102 |
-
chat_button = gr.Button("Отправить")
|
| 103 |
chat_output = gr.Textbox(label="Ответ", lines=8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
chat_button.click(fn=handle_chat_streaming, inputs=chat_input, outputs=chat_output)
|
| 106 |
|
| 107 |
if __name__ == "__main__":
|
| 108 |
demo.launch()
|
|
|
|
| 68 |
partial += delta
|
| 69 |
yield partial
|
| 70 |
|
| 71 |
+
def analyze_one_portfolio(text):
|
| 72 |
+
yield from analyze_portfolio_streaming(text, client)
|
| 73 |
|
| 74 |
|
| 75 |
def compare_analyze(text1, text2):
|
|
|
|
| 80 |
with gr.Blocks() as demo:
|
| 81 |
gr.Markdown("## 🧠 Анализ и сравнение инвестиционных портфелей Tradelink")
|
| 82 |
|
| 83 |
+
# 📊 АНАЛИЗ
|
| 84 |
with gr.Tab("📊 Анализ"):
|
| 85 |
portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
|
|
|
|
| 86 |
output_box = gr.Textbox(label="📈 Результат анализа", lines=15)
|
| 87 |
+
analyze_button = gr.Button("🔍 Проанализировать")
|
| 88 |
+
|
| 89 |
+
# stream=True включается через .stream()
|
| 90 |
analyze_button.click(
|
| 91 |
+
fn=analyze_one_portfolio,
|
| 92 |
inputs=portfolio_input,
|
| 93 |
+
outputs=output_box
|
| 94 |
+
).stream = True
|
| 95 |
|
| 96 |
+
# ⚖️ СРАВНЕНИЕ
|
| 97 |
with gr.Tab("⚖️ Сравнение"):
|
| 98 |
compare_input_1 = gr.Textbox(label="Портфель 1", placeholder="ea856c1b-...")
|
| 99 |
compare_input_2 = gr.Textbox(label="Портфель 2", placeholder="d52f55cc-...")
|
|
|
|
| 100 |
compare_output = gr.Textbox(label="📉 Результат сравнения", lines=20)
|
| 101 |
+
compare_button = gr.Button("📊 Сравнить")
|
| 102 |
|
| 103 |
+
compare_button.click(
|
| 104 |
+
fn=compare_analyze,
|
| 105 |
+
inputs=[compare_input_1, compare_input_2],
|
| 106 |
+
outputs=compare_output
|
| 107 |
+
).stream=True
|
| 108 |
+
|
| 109 |
+
# 💬 ДИАЛОГ
|
| 110 |
with gr.Tab("💬 Диалог"):
|
| 111 |
chat_input = gr.Textbox(label="Ваш вопрос", placeholder="Что такое TradeLink Passport?")
|
|
|
|
| 112 |
chat_output = gr.Textbox(label="Ответ", lines=8)
|
| 113 |
+
chat_button = gr.Button("Отправить")
|
| 114 |
+
|
| 115 |
+
chat_button.click(
|
| 116 |
+
fn=handle_chat_streaming,
|
| 117 |
+
inputs=chat_input,
|
| 118 |
+
outputs=chat_output
|
| 119 |
+
).stream = True
|
| 120 |
|
|
|
|
| 121 |
|
| 122 |
if __name__ == "__main__":
|
| 123 |
demo.launch()
|