Spaces:
Sleeping
Sleeping
QAway-to
commited on
Commit
·
4badfda
1
Parent(s):
af1b9a3
model change
Browse files- app.py +20 -0
- requirements.txt +2 -1
- table_view.py +16 -0
app.py
CHANGED
|
@@ -4,6 +4,9 @@ from prompts import TRADELINK_CONTEXT
|
|
| 4 |
from openai import OpenAI
|
| 5 |
from analyzer import analyze_portfolio_streaming
|
| 6 |
from comparer import compare_portfolio
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
api_key = os.getenv("featherless") #
|
| 9 |
client = OpenAI(
|
|
@@ -11,6 +14,14 @@ client = OpenAI(
|
|
| 11 |
api_key=api_key
|
| 12 |
)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def handle_chat_streaming(user_input):
|
| 15 |
response = client.chat.completions.create(
|
| 16 |
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
|
@@ -40,6 +51,7 @@ with gr.Blocks() as demo:
|
|
| 40 |
gr.Markdown("## 🧠 Анализ и сравнение инвестиционных портфелей Tradelink")
|
| 41 |
|
| 42 |
with gr.Tab("📊 Анализ"):
|
|
|
|
| 43 |
portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
|
| 44 |
analyze_button = gr.Button("🔍 Проанализировать")
|
| 45 |
output_box = gr.Textbox(label="📈 Результат анализа", lines=15)
|
|
@@ -63,5 +75,13 @@ with gr.Blocks() as demo:
|
|
| 63 |
|
| 64 |
chat_button.click(fn=handle_chat_streaming, inputs=chat_input, outputs=chat_output)
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
if __name__ == "__main__":
|
| 67 |
demo.launch()
|
|
|
|
| 4 |
from openai import OpenAI
|
| 5 |
from analyzer import analyze_portfolio_streaming
|
| 6 |
from comparer import compare_portfolio
|
| 7 |
+
from table_view import get_metrics_dataframe
|
| 8 |
+
import asyncio
|
| 9 |
+
|
| 10 |
|
| 11 |
api_key = os.getenv("featherless") #
|
| 12 |
client = OpenAI(
|
|
|
|
| 14 |
api_key=api_key
|
| 15 |
)
|
| 16 |
|
| 17 |
+
def show_metrics_table(pid: str):
|
| 18 |
+
try:
|
| 19 |
+
df = asyncio.run(get_metrics_dataframe(pid))
|
| 20 |
+
return df
|
| 21 |
+
except Exception as e:
|
| 22 |
+
return f"❌ Ошибка: {e}"
|
| 23 |
+
|
| 24 |
+
|
| 25 |
def handle_chat_streaming(user_input):
|
| 26 |
response = client.chat.completions.create(
|
| 27 |
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
|
|
|
| 51 |
gr.Markdown("## 🧠 Анализ и сравнение инвестиционных портфелей Tradelink")
|
| 52 |
|
| 53 |
with gr.Tab("📊 Анализ"):
|
| 54 |
+
|
| 55 |
portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
|
| 56 |
analyze_button = gr.Button("🔍 Проанализировать")
|
| 57 |
output_box = gr.Textbox(label="📈 Результат анализа", lines=15)
|
|
|
|
| 75 |
|
| 76 |
chat_button.click(fn=handle_chat_streaming, inputs=chat_input, outputs=chat_output)
|
| 77 |
|
| 78 |
+
with gr.Tab("📋 Метрики (таблица)"):
|
| 79 |
+
table_input = gr.Textbox(label="Введите portfolioId", placeholder="ea856c1b-...")
|
| 80 |
+
table_button = gr.Button("📥 Показать метрики")
|
| 81 |
+
table_output = gr.Dataframe(label="Таблица метрик", wrap=True)
|
| 82 |
+
|
| 83 |
+
table_button.click(fn=show_metrics_table, inputs=table_input, outputs=table_output)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
if __name__ == "__main__":
|
| 87 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
gradio>=4.29.0
|
| 2 |
openai>=1.30.1
|
| 3 |
requests
|
| 4 |
-
httpx
|
|
|
|
|
|
| 1 |
gradio>=4.29.0
|
| 2 |
openai>=1.30.1
|
| 3 |
requests
|
| 4 |
+
httpx
|
| 5 |
+
pandas
|
table_view.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from fetch import extract_portfolio_id, fetch_metrics_async
|
| 3 |
+
import asyncio
|
| 4 |
+
|
| 5 |
+
async def get_metrics_dataframe(portfolio_id: str) -> pd.DataFrame:
|
| 6 |
+
pid = extract_portfolio_id(portfolio_id)
|
| 7 |
+
if not pid:
|
| 8 |
+
raise ValueError("Некорректный portfolioId")
|
| 9 |
+
|
| 10 |
+
metrics = await fetch_metrics_async(pid)
|
| 11 |
+
if not metrics:
|
| 12 |
+
raise ValueError("Метрики не найдены")
|
| 13 |
+
|
| 14 |
+
df = pd.DataFrame.from_dict(metrics, orient='index', columns=["Значение"])
|
| 15 |
+
df.index.name = "Метрика"
|
| 16 |
+
return df
|