thisisdev commited on
Commit
5a14d1f
·
verified ·
1 Parent(s): f543b56

Code Updates

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py CHANGED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from transformers import AutoTokenizer, AutoModelForCausalLM
4
+ from langchain.chains import LLMChain
5
+ from langchain_core.prompts import PromptTemplate
6
+
7
+ # Load the Hugging Face API token from environment variables
8
+ hf_token = os.getenv('HF_TOKEN')
9
+ if hf_token is None:
10
+ raise ValueError("Hugging Face API token not found in environment variables.")
11
+
12
+ # Load the tokenizer and model using the API token
13
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-j-6B", use_auth_token=hf_token)
14
+ model = AutoModelForCausalLM.from_pretrained("EleutherAI/gpt-j-6B", use_auth_token=hf_token)
15
+
16
+ # Define your prompt template
17
+ prompt_template = PromptTemplate(
18
+ template="""
19
+ You are an AI language model trained to generate code for reinforcement learning models.
20
+ Given a description of a trading strategy, you need to generate a prompt that can be used to create code for a reinforcement learning model.
21
+ The prompt should be clear, concise, and include all necessary details to implement the strategy in code.
22
+
23
+ Here is the description of the trading strategy:
24
+ "{strategy}"
25
+
26
+ Based on this description, generate a proper prompt that can be used to create the code for a reinforcement learning model.
27
+ The prompt should include the following details:
28
+ 1. The type of reinforcement learning algorithm to be used (e.g., Q-learning, DQN, PPO, etc.).
29
+ 2. The main components of the algorithm (e.g., state space, action space, reward function).
30
+ 3. Any specific libraries or tools that should be used (e.g., TensorFlow, PyTorch, OpenAI Gym).
31
+ 4. Additional parameters or configurations that are important for the strategy.
32
+
33
+ Output the prompt in a way that another AI model can use to generate the code.
34
+ """,
35
+ input_variables=["strategy"]
36
+ )
37
+
38
+ chain = LLMChain(llm=model, prompt=prompt_template)
39
+
40
+ st.title("Text to Prompt Generator")
41
+ st.write("Enter some text and get a prompt for a reinforcement learning algorithm:")
42
+
43
+ text_input = st.text_area("Enter text here:")
44
+
45
+ if st.button("Generate Prompt"):
46
+ if text_input:
47
+ # Format the input into the template and generate the prompt
48
+ prompt = prompt_template.format(strategy=text_input)
49
+ st.write("Generated Prompt:")
50
+ st.write(prompt)
51
+ else:
52
+ st.write("Please enter some text to generate a prompt.")