subhannadeem1 commited on
Commit
ad46cf8
·
1 Parent(s): fc17af8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import yfinance as yf
4
+ import gradio as gr
5
+ # Load the tokenizer and model
6
+ tokenizer = AutoTokenizer.from_pretrained("huggingface_model")
7
+ model = AutoModelForSequenceClassification.from_pretrained("huggingface_model")
8
+
9
+ def predict_stock_price(day, month, year, input_text):
10
+ # Get the stock symbol from the input text
11
+ stock_symbol = extract_stock_symbol(input_text)
12
+
13
+ # Format the date for yfinance
14
+ start_date = f"{year}-{month:02d}-{day:02d}"
15
+ end_date = f"{year}-{month:02d}-{day:02d}"
16
+
17
+ # Get the historical stock data using yfinance
18
+ stock_data = yf.download(stock_symbol, start=start_date, end=end_date)
19
+
20
+ # Perform any necessary data preprocessing
21
+
22
+ # Tokenize the input text
23
+ inputs = tokenizer(input_text, return_tensors="pt")
24
+
25
+ # Forward pass through the model
26
+ outputs = model(**inputs)
27
+
28
+ # Get the predicted stock price
29
+ predicted_price = outputs.logits.item()
30
+
31
+ return predicted_price
32
+
33
+ def extract_stock_symbol(input_text):
34
+ # Implement the logic to extract the stock symbol from the input text
35
+ # For example, you can use regular expressions or a custom parsing algorithm
36
+ pass
37
+
38
+ # Define the Gradio interface
39
+ inputs = [
40
+ gr.inputs.Number(label="Day", min_value=1, max_value=31),
41
+ gr.inputs.Number(label="Month", min_value=1, max_value=12),
42
+ gr.inputs.Number(label="Year", min_value=2000, max_value=2022),
43
+ gr.inputs.Textbox(label="Input Text")
44
+ ]
45
+ output = gr.outputs.Textbox(label="Predicted Stock Price")
46
+
47
+ gr.Interface(fn=predict_stock_price, inputs=inputs, outputs=output).launch()