Spaces:
Sleeping
Sleeping
Download app.py from TrancheVest/RiskAssessmentEngine: direct link, hf CLI and curl.
- Browser
- Download file 2.05 kB
-
https://huggingface.co/spaces/TrancheVest/RiskAssessmentEngine/resolve/main/app.py
- Command line
-
hf download hf://spaces/TrancheVest/RiskAssessmentEngine/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TrancheVest/RiskAssessmentEngine/resolve/main/app.py
2.05 kB
| 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() | |