File size: 1,234 Bytes
3205dc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForCausalLM

# Load your fine-tuned model from Hugging Face Hub
model_name = "Deepesh-001/RagFin-Ai"  # Replace with actual name
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

# Function to generate response from user query + context
def generate_answer(query, context):
    input_text = f"Context: {context}\n\nQuestion: {query}\nAnswer:"
    inputs = tokenizer(input_text, return_tensors="pt")
    outputs = model.generate(**inputs, max_length=300, do_sample=True, top_k=50)
    answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return answer

# Gradio UI
iface = gr.Interface(
    fn=generate_answer,
    inputs=[
        gr.Textbox(label="User Query", placeholder="How can I save tax on ₹15 lakhs income?"),
        gr.Textbox(label="Context", placeholder="Provide some financial context or let it be blank...")
    ],
    outputs="text",
    title="Financial LLM - Indian Tax Advisor",
    description="Ask anything about Indian tax planning, deductions, or financial strategies."
)

# Run the app
if __name__ == "__main__":
    iface.launch()