Spaces:
Runtime error
Runtime error
| 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() | |