File size: 2,052 Bytes
efe4ca4
 
 
 
 
 
 
 
 
 
 
a2df663
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
efe4ca4
a2df663
 
5231ae5
a2df663
 
 
efe4ca4
 
 
a2df663
 
 
efe4ca4
 
 
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
69
70
71
import gradio as gr
import time
from utils import (
    get_question,
    get_answer,
    evaluate_expertise,
    get_crypto_data,
)


def run_chat(crypto, data_span):
    # Validate inputs
    valid_cryptos = ["btc", "eth", "virtual", "bnb"]
    valid_spans = ["24h", "7d", "14d", "30d", "60d"]
    if crypto not in valid_cryptos or data_span not in valid_spans:
        yield [("๐Ÿค–", "โŒ Invalid crypto or data span selection")], []
        return

    crypto_data = get_crypto_data(crypto, data_span)
    chat_history = []
    previous_qa = ""
    qa_history = []

    for _ in range(5):
        # --- QUESTION ---
        question = get_question(previous_qa)
        # append as a right-only message
        chat_history.append(("", question.content))
        yield chat_history, []  # show question
        time.sleep(1)

        # --- ANSWER ---
        answer = get_answer(question.content, previous_qa, crypto_data)
        # append as a left-only message
        chat_history.append((answer.content, ""))
        yield chat_history, []  # show answer

        # track for final evaluation
        qa_history.append({"question": question.content, "answer": answer.content})
        previous_qa += f"\nQ: {question.content}\nA: {answer.content}\n"
        time.sleep(1)

    # --- FINAL EVALUATION ---
    evaluation = evaluate_expertise(qa_history)
    chat_history.append(("๐Ÿ“Š Evaluation:", evaluation.content))
    yield chat_history, chat_history


with gr.Blocks() as demo:
    gr.Markdown("## ๐Ÿง  TranchVest AI - Crypto Behavior Analysis")

    with gr.Row():
        crypto_dropdown = gr.Dropdown(
            ["btc", "eth", "virtual", "bnb"], label="Select Crypto"
        )
        span_dropdown = gr.Dropdown(
            ["24h", "7d", "14d", "30d", "60d"], label="Select Data Span"
        )
        start_btn = gr.Button("Start Chat")

    chatbot = gr.Chatbot(height=600)
    state = gr.State([])

    start_btn.click(
        run_chat,
        [crypto_dropdown, span_dropdown],
        [chatbot, state],
    )

demo.launch()