Spaces:
Sleeping
Sleeping
still having errors? fixed indentation
Browse files4 unmodified lines5678910117 unmodified lines1920212223242526272829304 unmodified lines353637383940414243444546474849505118 unmodified lines707172737475767712 unmodified lines9091929394959697984 unmodified linesimport numpy as npimport faissfrom sentence_transformers import SentenceTransformerfrom bs4 import BeautifulSoup #help clean up the HTML tags in my JSON datahf_token = os.getenv("HF_Token")client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=hf_token)7 unmodified lineschunks.extend(i.split(". "))cleaned_chunks = []for chunk in chunks:chunk = chunk.strip()if len(chunk) > 0:cleaned_chunks.append(chunk)return cleaned_chunksdef prepare_docs():4 unmodified linesfor item in raw_data:soup = BeautifulSoup(item['popup'], 'html.parser')raw_html_text = soup.get_text(separator=" ")chunks = preprocess_text(raw_html_text)for chunk in chunks:all_processed_chunks.append(chunk)return all_processed_chunksprocessed_data = prepare_docs()embeddings = embed_model.encode(processed_data)index = faiss.IndexFlatL2(embeddings.shape[1])index.add(np.array(embeddings).astype('float32'))18 unmodified linesmessages = [{"role": "system", "content": system_prompt}]for msg in history:messages.append(msg)messages.append({"role": "user", "content": message})12 unmodified lineschatbot = gr.ChatInterface(respond,type="messages",title="CityScout: Unique Spot Finder",description="Tell me your city and interests to find a cool spot!")chatbot.launch()4 unmodified lines5678910117 unmodified lines192021222324252627284 unmodified lines3334353637383940414243444546474818 unmodified lines67686970717273747512 unmodified lines8889909192939495964 unmodified linesimport numpy as npimport faissfrom sentence_transformers import SentenceTransformerfrom bs4 import BeautifulSouphf_token = os.getenv("HF_Token")client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=hf_token)7 unmodified lineschunks.extend(i.split(". "))cleaned_chunks = []for chunk in chunks:chunk = chunk.strip()if len(chunk) > 0:cleaned_chunks.append(chunk)return cleaned_chunksdef prepare_docs():4 unmodified linesfor item in raw_data:soup = BeautifulSoup(item['popup'], 'html.parser')name = soup.find(class_='infobox-title').get_text() if soup.find(class_='infobox-title') else "Unknown Spot"raw_html_text = soup.get_text(separator=" ")chunks = preprocess_text(raw_html_text)for chunk in chunks:all_processed_chunks.append(f"[{name}]: {chunk}")return all_processed_chunksprocessed_data = prepare_docs()embeddings = embed_model.encode(processed_data)index = faiss.IndexFlatL2(embeddings.shape[1])index.add(np.array(embeddings).astype('float32'))18 unmodified linesmessages = [{"role": "system", "content": system_prompt}]for user_msg, assistant_msg in history:if user_msg: messages.append({"role": "user", "content": user_msg})if assistant_msg: messages.append({"role": "assistant", "content": assistant_msg})messages.append({"role": "user", "content": message})12 unmodified lineschatbot = gr.ChatInterface(respond,title="CityScout: Unique Spot Finder",description="Tell me your city or interests (e.g. 'mummies' or 'New York')!")if __name__ == "__main__":chatbot.launch()
app.py+12-14