Spaces:
Sleeping
Sleeping
| # git clone https://huggingface.co/spaces/Everwell-KWK/Everwell | |
| import gradio as gr | |
| import random | |
| from huggingface_hub import InferenceClient | |
| from datasets import load_dataset | |
| from sentence_transformers import SentenceTransformer | |
| import torch | |
| import pandas as pd | |
| file_path = "drug list for ai medication chatbot - Sheet1" | |
| dataset = load_dataset("csv", data_files="drug list for ai medication chatbot - Sheet1.csv") | |
| with open("drug list for ai medication chatbot - Sheet1.csv", "r", encoding = "utf-8") as file: | |
| file_path = file.read() | |
| # print(file_path) | |
| client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") | |
| messages = [{"role": "system", "content":"You are a chatbot specializing in helping the user track medications. This applies to both short-term medications such as antibiotics and like, and long-term medications like antidepressants and beta-blockers"}] | |
| cleaned_drug_list = file_path.strip() | |
| chunked_list = cleaned_drug_list.split("\n") | |
| cleaned_chunks = [] | |
| for chunked in chunked_list: #loops through database & adds it to the modifications done by chunked_list | |
| stripped_list = chunked.strip() | |
| if stripped_list: | |
| cleaned_chunks.append(stripped_list) # appends to empty in cleaned_chunks = [] | |
| #print(cleaned_chunks) | |
| df = pd.read_csv("drug list for ai medication chatbot - Sheet1.csv") | |
| print(df) | |
| def respond(message, history): | |
| if not history: | |
| return "Hello! How can I assist you today?" | |
| messages.append({"role": "user", "content": message}) | |
| response = client.chat_completion( | |
| messages, | |
| max_tokens=10000 | |
| ) | |
| # Extract response safely | |
| try: | |
| return response['choices'][0]['message']['content'].strip() | |
| except Exception as e: | |
| return f"Sorry, something went wrong: {e}" | |
| chatbot = gr.ChatInterface( | |
| respond, | |
| type="messages", | |
| title="EverWell", | |
| theme=gr.themes.Glass(), | |
| examples=[ | |
| ["What medication am I on?"], | |
| ["How much medication do I have left?"], | |
| ["Can we chat?"] | |
| ], | |
| cache_examples=False # <- important! | |
| ) | |
| chatbot.launch() | |
| # When chatbot is opened, it needs to greet the user with a generated response like "Hello, User! What medication can I help you figure out today?" |