Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,20 @@
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Trainer, TrainingArguments, DataCollatorForSeq2Seq
|
| 2 |
-
from datasets import Dataset
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
| 5 |
import os
|
|
|
|
| 6 |
|
| 7 |
# ------------------------------
|
| 8 |
-
# 1.
|
| 9 |
# ------------------------------
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
{"input": "What to do if I have a headache?", "output": "I understand headaches are frustrating. Try meditation, rest, and stay hydrated."},
|
| 13 |
-
{"input": "My child has fever, what do I do?", "output": "Give paracetamol, keep them hydrated, and if fever persists, consult a doctor."},
|
| 14 |
-
{"input": "Who can I contact for fever treatment?", "output": "You can reach Dr. Ankit Verma at +91-9876543210 or Dr. Priya Singh at +91-9123456780."},
|
| 15 |
-
{"input": "I feel dizzy, what should I do?", "output": "Sit down, drink water, and rest. If it continues, see a doctor."},
|
| 16 |
-
{"input": "I am anxious and need help.", "output": "Feeling anxious is okay. Try deep breathing. You can also speak with Dr. Richa Nair at +91-9874455667."},
|
| 17 |
-
{"input": "I have mild back pain.", "output": "Gentle stretching and rest can help. For consultation, Dr. Amit Khanna +91-9988774455 is available."},
|
| 18 |
-
{"input": "My child has a cough and cold.", "output": "Dr. Sneha Kapoor at +91-9871122334 and Dr. Arjun Mehta at +91-9112233445 can assist. Keep your child warm."}
|
| 19 |
-
]
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
dataset = Dataset.from_list(data)
|
| 22 |
|
| 23 |
# ------------------------------
|
|
@@ -64,7 +61,7 @@ trainer = Trainer(
|
|
| 64 |
model=model,
|
| 65 |
args=training_args,
|
| 66 |
train_dataset=tokenized_dataset,
|
| 67 |
-
tokenizer=tokenizer,
|
| 68 |
data_collator=data_collator
|
| 69 |
)
|
| 70 |
|
|
@@ -81,7 +78,7 @@ model = AutoModelForSeq2SeqLM.from_pretrained(OUTPUT_DIR)
|
|
| 81 |
tokenizer = AutoTokenizer.from_pretrained(OUTPUT_DIR)
|
| 82 |
|
| 83 |
# ------------------------------
|
| 84 |
-
# 7. Gradio UI (
|
| 85 |
# ------------------------------
|
| 86 |
def respond(user_input, chat_history):
|
| 87 |
inputs = tokenizer(user_input, return_tensors="pt")
|
|
@@ -92,8 +89,13 @@ def respond(user_input, chat_history):
|
|
| 92 |
chat_history.append(("Bot", reply))
|
| 93 |
return chat_history, chat_history
|
| 94 |
|
| 95 |
-
with gr.Blocks(
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
chatbot = gr.Chatbot()
|
| 98 |
state = gr.State([])
|
| 99 |
with gr.Row():
|
|
@@ -103,4 +105,3 @@ with gr.Blocks() as demo:
|
|
| 103 |
msg.submit(respond, [msg, state], [chatbot, state])
|
| 104 |
|
| 105 |
demo.launch()
|
| 106 |
-
|
|
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Trainer, TrainingArguments, DataCollatorForSeq2Seq
|
| 2 |
+
from datasets import Dataset, load_dataset
|
| 3 |
import gradio as gr
|
| 4 |
import torch
|
| 5 |
import os
|
| 6 |
+
import pandas as pd
|
| 7 |
|
| 8 |
# ------------------------------
|
| 9 |
+
# 1. Load dataset from CSV
|
| 10 |
# ------------------------------
|
| 11 |
+
CSV_FILE = "remedies.csv" # path to your CSV
|
| 12 |
+
df = pd.read_csv(CSV_FILE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Prepare dataset in HuggingFace format
|
| 15 |
+
data = []
|
| 16 |
+
for _, row in df.iterrows():
|
| 17 |
+
data.append({"input": row['symptoms'], "output": row['response']})
|
| 18 |
dataset = Dataset.from_list(data)
|
| 19 |
|
| 20 |
# ------------------------------
|
|
|
|
| 61 |
model=model,
|
| 62 |
args=training_args,
|
| 63 |
train_dataset=tokenized_dataset,
|
| 64 |
+
tokenizer=tokenizer,
|
| 65 |
data_collator=data_collator
|
| 66 |
)
|
| 67 |
|
|
|
|
| 78 |
tokenizer = AutoTokenizer.from_pretrained(OUTPUT_DIR)
|
| 79 |
|
| 80 |
# ------------------------------
|
| 81 |
+
# 7. Gradio UI (blue & white)
|
| 82 |
# ------------------------------
|
| 83 |
def respond(user_input, chat_history):
|
| 84 |
inputs = tokenizer(user_input, return_tensors="pt")
|
|
|
|
| 89 |
chat_history.append(("Bot", reply))
|
| 90 |
return chat_history, chat_history
|
| 91 |
|
| 92 |
+
with gr.Blocks(css="""
|
| 93 |
+
body {background-color: #f0f8ff;}
|
| 94 |
+
.gradio-container {border-radius: 15px; padding: 20px; background-color: #ffffff;}
|
| 95 |
+
.chatbot-message.user {background-color: #cce5ff; color: #000;}
|
| 96 |
+
.chatbot-message.bot {background-color: #e6f0ff; color: #000;}
|
| 97 |
+
""") as demo:
|
| 98 |
+
gr.Markdown("<h1 style='text-align:center; color:#007BFF;'>💊 Health Remedies Chatbot</h1>")
|
| 99 |
chatbot = gr.Chatbot()
|
| 100 |
state = gr.State([])
|
| 101 |
with gr.Row():
|
|
|
|
| 105 |
msg.submit(respond, [msg, state], [chatbot, state])
|
| 106 |
|
| 107 |
demo.launch()
|
|
|