Download app.py from AventIQ-AI/t5-stockmarket-qa-chatbot: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/spaces/AventIQ-AI/t5-stockmarket-qa-chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/AventIQ-AI/t5-stockmarket-qa-chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AventIQ-AI/t5-stockmarket-qa-chatbot/resolve/main/app.py
1.54 kB
| import gradio as gr | |
| from transformers import pipeline | |
| def stockmarket_qa(question): | |
| model_name = "AventIQ-AI/t5-stockmarket-qa-chatbot" | |
| print("Loading model...") | |
| generator = pipeline("text2text-generation", model=model_name, device=0) # Use GPU if available | |
| # Correcting the input format based on the model's README | |
| instruction = "question: " # If required by the model | |
| input_text = f"{instruction}{question}" | |
| print(f"Processing input: {input_text}") | |
| response = generator(input_text, max_new_tokens=200)[0]['generated_text'] | |
| print(f"Response: {response}") | |
| return response | |
| iface = gr.Interface( | |
| fn=stockmarket_qa, | |
| inputs=gr.Textbox(label="π Ask a Stock Market Question", placeholder="Enter your query about the stock market...", lines=3), | |
| outputs=gr.Textbox(label="π‘ Expert Answer", interactive=True), | |
| title="π AI-Powered Stock Market Q&A Chatbot", | |
| description="π€ Enter a stock market-related question, and the AI chatbot will generate a detailed response based on financial knowledge.", | |
| theme="compact", | |
| allow_flagging="never", | |
| examples=[ | |
| ["What are the best stocks to invest in right now?"], | |
| ["How does inflation affect stock prices?"], | |
| ["What is technical analysis in stock trading?"], | |
| ["Explain the difference between a bull and bear market."], | |
| ["How do interest rates impact the stock market?"] | |
| ], | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |