Spaces:
Sleeping
Sleeping
File size: 2,538 Bytes
ab0a6c9 d0db547 7f2f713 8caee6c c54262a 00ddeb7 8b21f63 c30b7eb d0db547 8370475 d02533f a4c20c7 d02533f a928dd2 d2b7cd0 d02533f 5e3de11 00ddeb7 d97fa05 a928dd2 6067413 984eb4a a928dd2 984eb4a 6067413 d97fa05 a928dd2 6067413 d97fa05 d02533f a928dd2 6067413 a928dd2 6067413 06417df 8caee6c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
import gradio as gr
import os
from prompts import TRADELINK_CONTEXT
from openai import OpenAI
from analyzer import analyze_portfolio_streaming
from comparer import compare_portfolio
api_key = os.getenv("featherless") #
client = OpenAI(
base_url="https://api.featherless.ai/v1",
api_key=api_key
)
def handle_chat_streaming(user_input):
response = client.chat.completions.create(
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
messages=[
{"role": "system", "content": TRADELINK_CONTEXT},
{"role": "user", "content": user_input}
],
stream=True
)
partial = ""
for chunk in response:
delta = chunk.choices[0].delta.content
if delta:
partial += delta
yield partial
def analyze_one_portfolio(text):
yield from analyze_portfolio_streaming(text, client)
def compare_analyze(text1, text2):
yield from compare_portfolio(text1, text2, client)
# Gradio интерфейс
with gr.Blocks() as demo:
gr.Markdown("## 🧠 Анализ и сравнение инвестиционных портфелей Tradelink")
with gr.Tab("📊 Анализ"):
portfolio_input = gr.Textbox(label="Введите ссылку или portfolioId", placeholder="ea856c1b-...")
analyze_button = gr.Button("🔍 Проанализировать")
output_box = gr.Textbox(label="📈 Результат анализа", lines=15)
analyze_button.click(
fn=analyze_one_portfolio,
inputs=portfolio_input,
outputs=output_box # Textbox
)
with gr.Tab("⚖️ Сравнение"):
compare_input_1 = gr.Textbox(label="Портфель 1", placeholder="ea856c1b-...")
compare_input_2 = gr.Textbox(label="Портфель 2", placeholder="d52f55cc-...")
compare_button = gr.Button("📊 Сравнить")
compare_output = gr.Textbox(label="📉 Результат сравнения", lines=20)
compare_button.click(fn=compare_analyze, inputs=[compare_input_1, compare_input_2], outputs=compare_output)
with gr.Tab("💬 Диалог"):
chat_input = gr.Textbox(label="Ваш вопрос", placeholder="Что такое TradeLink Passport?")
chat_button = gr.Button("Отправить")
chat_output = gr.Textbox(label="Ответ", lines=8)
chat_button.click(fn=handle_chat_streaming, inputs=chat_input, outputs=chat_output)
if __name__ == "__main__":
demo.launch()
|