acecalisto3 commited on
Commit
1158227
1 Parent(s): 609e2ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -34
app.py CHANGED
@@ -8,39 +8,7 @@ from io import StringIO
8
  import openai
9
  import sys
10
  import torch
11
-
12
- # Set the auth token
13
- st.set_page_config(hf_token="YOUR_AUTH_TOKEN")
14
-
15
- # Load pre-trained RAG retriever
16
- rag_retriever = RagRetriever.from_pretrained("facebook/rag-base")
17
-
18
- # Load pre-trained chat model
19
- chat_model = AutoModelForSeq2SeqLM.from_pretrained("google/chat-model-base")
20
-
21
- # Load tokenizer
22
- tokenizer = AutoTokenizer.from_pretrained("google/chat-model-base")
23
-
24
- def process_input(user_input):
25
- # Input pipeline: Tokenize and preprocess user input
26
- input_ids = tokenizer(user_input, return_tensors="pt").input_ids
27
- attention_mask = tokenizer(user_input, return_tensors="pt").attention_mask
28
-
29
- # RAG model: Generate response
30
- with torch.no_grad():
31
- output = rag_retriever(input_ids, attention_mask=attention_mask)
32
- response = output.generator_outputs[0].sequences[0]
33
-
34
- # Chat model: Refine response
35
- chat_input = tokenizer(response, return_tensors="pt")
36
- chat_input["input_ids"] = chat_input["input_ids"].unsqueeze(0)
37
- chat_input["attention_mask"] = chat_input["attention_mask"].unsqueeze(0)
38
- with torch.no_grad():
39
- chat_output = chat_model(**chat_input)
40
- refined_response = chat_output.sequences[0]
41
-
42
- # Output pipeline: Return final response
43
- return refined_response
44
 
45
  # Set your OpenAI API key here
46
  openai.api_key = "YOUR_OPENAI_API_KEY"
@@ -290,6 +258,9 @@ st.title("AI Agent Creator")
290
  st.sidebar.title("Navigation")
291
  app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
292
 
 
 
 
293
  if app_mode == "AI Agent Creator":
294
  # AI Agent Creator
295
  st.header("Create an AI Agent from Text")
@@ -455,4 +426,8 @@ elif app_mode == "Workspace Chat App":
455
  st.write("Autonomous Build Summary:")
456
  st.write(summary)
457
  st.write("Next Step:")
458
- st.write(next_step)
 
 
 
 
 
8
  import openai
9
  import sys
10
  import torch
11
+ from huggingface_hub import hf_hub_url, cached_download, HfApi
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  # Set your OpenAI API key here
14
  openai.api_key = "YOUR_OPENAI_API_KEY"
 
258
  st.sidebar.title("Navigation")
259
  app_mode = st.sidebar.selectbox("Choose the app mode", ["AI Agent Creator", "Tool Box", "Workspace Chat App"])
260
 
261
+ # Get Hugging Face token from secrets.toml
262
+ hf_token = st.secrets["huggingface"]["hf_token"]
263
+
264
  if app_mode == "AI Agent Creator":
265
  # AI Agent Creator
266
  st.header("Create an AI Agent from Text")
 
426
  st.write("Autonomous Build Summary:")
427
  st.write(summary)
428
  st.write("Next Step:")
429
+ st.write(next_step)
430
+
431
+ # Use the hf_token to interact with the Hugging Face API
432
+ api = HfApi(token=hf_token)
433
+ # ... (your logic to deploy the Space using the API)