Spaces:
Paused
Paused
Update app.py
Browse files4 unmodified lines56789101112131415161723 unmodified lines414243444546383 unmodified lines4304314324334 unmodified linesimport blackfrom pylint import lintfrom io import StringIOimport openaiimport sysimport torchfrom huggingface_hub import hf_hub_url, cached_download, HfApi# Set your OpenAI API key hereopenai.api_key = "YOUR_OPENAI_API_KEY"HUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"PROJECT_ROOT = "projects"23 unmodified lines"facebook/bart-large-cnn", # Good for text-to-code tasks]class AIAgent:def __init__(self, name, description, skills):self.name = name383 unmodified lines# Use the hf_token to interact with the Hugging Face APIapi = HfApi(token=hf_token)# ... (your logic to deploy the Space using the API)4 unmodified lines567891011121314151623 unmodified lines404142434445464748495051525354555657585960616263646566676869707172737475383 unmodified lines4594604614624634644654664 unmodified linesimport blackfrom pylint import lintfrom io import StringIOimport sysimport torchfrom huggingface_hub import hf_hub_url, cached_download, HfApi# Set your Hugging Face API key herehf_token = "YOUR_HUGGING_FACE_API_KEY" # Replace with your actual tokenHUGGING_FACE_REPO_URL = "https://huggingface.co/spaces/acecalisto3/DevToolKit"PROJECT_ROOT = "projects"23 unmodified lines"facebook/bart-large-cnn", # Good for text-to-code tasks]# Load pre-trained RAG retrieverrag_retriever = RagRetriever.from_pretrained("facebook/rag-token-base") # Use a Hugging Face RAG model# Load pre-trained chat modelchat_model = AutoModelForSeq2SeqLM.from_pretrained("microsoft/DialoGPT-medium") # Use a Hugging Face chat model# Load tokenizertokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")def process_input(user_input):# Input pipeline: Tokenize and preprocess user inputinput_ids = tokenizer(user_input, return_tensors="pt").input_idsattention_mask = tokenizer(user_input, return_tensors="pt").attention_mask# RAG model: Generate responsewith torch.no_grad():output = rag_retriever(input_ids, attention_mask=attention_mask)response = output.generator_outputs[0].sequences[0]# Chat model: Refine responsechat_input = tokenizer(response, return_tensors="pt")chat_input["input_ids"] = chat_input["input_ids"].unsqueeze(0)chat_input["attention_mask"] = chat_input["attention_mask"].unsqueeze(0)with torch.no_grad():chat_output = chat_model(**chat_input)refined_response = chat_output.sequences[0]# Output pipeline: Return final responsereturn refined_responseclass AIAgent:def __init__(self, name, description, skills):self.name = name383 unmodified lines# Use the hf_token to interact with the Hugging Face APIapi = HfApi(token=hf_token)# Function to create a Space on Hugging Facedef create_space(api, name, description, public, files, entrypoint="launch.py"):url = f"{hf_hub_url()}spaces/{name}/prepare-repo"headers = {"Authorization": f"Bearer {api.access_token}"}</s>
app.py+37-4