Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
import streamlit as st
|
| 4 |
-
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer
|
| 5 |
import black
|
| 6 |
from pylint import lint
|
| 7 |
from io import StringIO
|
| 8 |
-
import openai
|
| 9 |
import sys
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"
|
| 15 |
PROJECT_ROOT = "projects"
|
|
@@ -41,7 +41,6 @@ class AIAgent:
|
|
| 41 |
agent_prompt = f"""
|
| 42 |
As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:
|
| 43 |
{skills_str}
|
| 44 |
-
|
| 45 |
I am confident that I can leverage my expertise to assist you in developing and deploying cutting-edge web applications. Please feel free to ask any questions or present any challenges you may encounter.
|
| 46 |
"""
|
| 47 |
return agent_prompt
|
|
@@ -68,6 +67,9 @@ I am confident that I can leverage my expertise to assist you in developing and
|
|
| 68 |
|
| 69 |
return summary, next_step
|
| 70 |
|
|
|
|
|
|
|
|
|
|
| 71 |
def save_agent_to_file(agent):
|
| 72 |
"""Saves the agent's prompt to a file."""
|
| 73 |
if not os.path.exists(AGENT_DIRECTORY):
|
|
@@ -102,7 +104,9 @@ def chat_interface_with_agent(input_text, agent_name):
|
|
| 102 |
try:
|
| 103 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 104 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 105 |
-
generator = pipeline("text-generation", model=model, tokenizer=tokenizer
|
|
|
|
|
|
|
| 106 |
except EnvironmentError as e:
|
| 107 |
return f"Error loading model: {e}"
|
| 108 |
|
|
@@ -113,7 +117,7 @@ def chat_interface_with_agent(input_text, agent_name):
|
|
| 113 |
if input_ids.shape[1] > max_input_length:
|
| 114 |
input_ids = input_ids[:, :max_input_length]
|
| 115 |
|
| 116 |
-
outputs =
|
| 117 |
input_ids, max_new_tokens=50, num_return_sequences=1, do_sample=True,
|
| 118 |
pad_token_id=tokenizer.eos_token_id # Set pad_token_id to eos_token_id
|
| 119 |
)
|
|
|
|
| 1 |
import os
|
| 2 |
import subprocess
|
| 3 |
import streamlit as st
|
| 4 |
+
from transformers import pipeline, AutoModelForCausalLM, AutoTokenizer, AutoConfig, AutoModel, pipeline_utils
|
| 5 |
import black
|
| 6 |
from pylint import lint
|
| 7 |
from io import StringIO
|
|
|
|
| 8 |
import sys
|
| 9 |
+
from huggingface_hub import notebook_login
|
| 10 |
|
| 11 |
+
notebook_login()
|
| 12 |
+
hf_token = "YOUR_HF_TOKEN"
|
| 13 |
|
| 14 |
HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"
|
| 15 |
PROJECT_ROOT = "projects"
|
|
|
|
| 41 |
agent_prompt = f"""
|
| 42 |
As an elite expert developer, my name is {self.name}. I possess a comprehensive understanding of the following areas:
|
| 43 |
{skills_str}
|
|
|
|
| 44 |
I am confident that I can leverage my expertise to assist you in developing and deploying cutting-edge web applications. Please feel free to ask any questions or present any challenges you may encounter.
|
| 45 |
"""
|
| 46 |
return agent_prompt
|
|
|
|
| 67 |
|
| 68 |
return summary, next_step
|
| 69 |
|
| 70 |
+
def load_hf_token():
|
| 71 |
+
return hf_token
|
| 72 |
+
|
| 73 |
def save_agent_to_file(agent):
|
| 74 |
"""Saves the agent's prompt to a file."""
|
| 75 |
if not os.path.exists(AGENT_DIRECTORY):
|
|
|
|
| 104 |
try:
|
| 105 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 106 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 107 |
+
generator = pipeline("text-generation", model=model, tokenizer=tokenizer,
|
| 108 |
+
framework="pt",
|
| 109 |
+
model_kwargs={'load_in_8bit': True, 'torch_dtype': torch.float16})
|
| 110 |
except EnvironmentError as e:
|
| 111 |
return f"Error loading model: {e}"
|
| 112 |
|
|
|
|
| 117 |
if input_ids.shape[1] > max_input_length:
|
| 118 |
input_ids = input_ids[:, :max_input_length]
|
| 119 |
|
| 120 |
+
outputs = generator(
|
| 121 |
input_ids, max_new_tokens=50, num_return_sequences=1, do_sample=True,
|
| 122 |
pad_token_id=tokenizer.eos_token_id # Set pad_token_id to eos_token_id
|
| 123 |
)
|