File size: 1,752 Bytes
76e0e92 d188bb3 c94cf22 f76cce9 e9ee13d f76cce9 d188bb3 287ffa2 76e0e92 d188bb3 f201ba6 d188bb3 f201ba6 d188bb3 11cc572 d188bb3 f201ba6 d188bb3 |
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 |
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
import torch
import gradio as gr
import os
token = os.getenv("MyToken2")
if not token:
raise ValueError("Hugging Face token not found!")
model_id = "meta-llama/Llama-3.2-1B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id, token=token)
model = AutoModelForCausalLM.from_pretrained(model_id, token=token)
pipe = pipeline(
"text-generation",
model=model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
def generate_response(financial_goal, risk_tolerance, investment_horizon, monthly_income, monthly_expense, current_savings):
prompt = f"""
I need financial advice based on the following information:
Financial Goal: {financial_goal}
Risk Tolerance: {risk_tolerance}
Investment Horizon (years): {investment_horizon}
Monthly Income (€): {monthly_income}
Monthly Expense (€): {monthly_expense}
Current Savings (€): {current_savings}
Please provide a detailed financial plan.
"""
outputs = pipe(
prompt,
max_new_tokens=300,
)
response = outputs[0]["generated_text"]
return response
iface = gr.Interface(
fn=generate_response,
inputs=[
gr.Textbox(label="Financial Goal"),
gr.Textbox(label="Risk Tolerance"),
gr.Number(label="Investment Horizon (years)"),
gr.Number(label="Monthly Income (€)"),
gr.Number(label="Monthly Expense (€)"),
gr.Number(label="Current Savings (€)"),
],
outputs=gr.Textbox(label="Financial Advice"),
title="Financial Advisor",
description="Enter your financial details to receive personalized advice.",
)
# Launch the Gradio app
iface.launch() |