import requests import pandas as pd import io from transformers import…
- User
import requests import pandas as pd import io from transformers import AutoModelForCausalLM, AutoTokenizer import torchaudio from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer from gtts import gTTS import tempfile import torch import gradio as gr
Device configuration
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
Load conversational language model
language_model_name = "microsoft/DialoGPT-medium" # Use a suitable model tokenizer = AutoTokenizer.from_pretrained(language_model_name) language_model = AutoModelForCausalLM.from_pretrained(language_model_name).to(device)
Load Speech-to-Text (Wav2Vec2) model
stt_model_name = "facebook/wav2vec2-base-960h" stt_tokenizer = Wav2Vec2Tokenizer.from_pretrained(stt_model_name) stt_model = Wav2Vec2ForCTC.from_pretrained(stt_model_name).to(device)
URL of the GitHub raw CSV file
CSV_URL = "https://raw.githubusercontent.com/your-username/your-repo/main/medical_advice.csv"
def load_medical_advice(): try: response = requests.get(CSV_URL) response.raise_for_status() # Ensure the request was successful csv_data = response.content.decode('utf-8') advice_df = pd.read_csv(io.StringIO(csv_data)) return pd.Series(advice_df.advice.values, index=advice_df.symptom).to_dict() except requests.exceptions.RequestException as e: print(f"Error loading medical advice: {e}") return {}
Load the advice dictionary
medical_advice_data = load_medical_advice()
def transcribe_audio(audio_path): # Existing transcription code... waveform, sample_rate = torchaudio.load(audio_path) if sample_rate != 16000: resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000) waveform = resampler(waveform) input_values = stt_tokenizer(waveform.squeeze().numpy(), return_tensors="pt", sampling_rate=16000).input_values.to(device)
with torch.no_grad(): logits = stt_model(input_values).logits predicted_ids = torch.argmax(logits, dim=-1) return stt_tokenizer.batch_decode(predicted_ids)[0].lower()def get_medical_advice(user_input): for key in medical_advice_data: if key in user_input: return medical_advice_data[key] return "I'm sorry, I don't have specific advice on that. Please consult a healthcare professional."
def get_bot_response(user_input): global chat_history_ids new_user_input_ids = tokenizer.encode(user_input + tokenizer.eos_token, return_tensors='pt').to(device) if chat_history_ids is not None: bot_input_ids = torch.cat([chat_history_ids, new_user_input_ids], dim=-1) else: bot_input_ids = new_user_input_ids
chat_history_ids = language_model.generate( bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id, no_repeat_ngram_size=3, do_sample=True, top_p=0.95, temperature=0.7 ) response = tokenizer.decode(chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True) return response - Assistant
- User
Provide me a medical advise data
- Assistant
Certainly! Here's a simple example of how a medical advice CSV file might look, with some basic symptoms and corresponding advice:
symptom,advice headache,Drink plenty of water and rest; consider taking a pain reliever if necessary. cough,Stay hydrated and consider using a humidifier; consult a doctor if persistent. fever,Ensure adequate hydration and rest; consider over-the-counter fever reducers. nausea,Try ginger tea or peppermint; stay hydrated and avoid greasy foods. back pain,Maintain good posture and consider gentle stretching exercises; apply a cold or hot pack. sore throat,Gargle warm salt water and stay hydrated; consider honey or throat lozenges. dizziness,Sit or lie down immediately; drink water slowly. allergy,Identify and avoid triggers; consider over-the-counter antihistamines. constipation,Increase fiber intake and drink plenty of water; try to stay active. insomnia,Maintain a regular sleep schedule and create a restful environment; avoid caffeine before bed. - User
Provide me a medical data
- Assistant
Sure, I'll provide some sample medical advice data that you can use in a CSV format. This data includes some common symptoms and general advice for each. Again, keep in mind that this advice is very general and for demonstration purposes only. Always consult a professional for medical concerns.
Sample Medical Advice Data (CSV Format):
symptom,advice headache,Ensure you are staying hydrated, rest in a quiet and dark place, and consider using over-the-counter pain relief if necessary. cough,Stay well-hydrated, use a humidifier to moisten the air, and see a doctor if your cough persists. fever,Drink plenty of fluids, rest, and use fever-reducing medications like acetaminophen or ibuprofen as needed. nausea,Try eating smaller, bland meals, stay hydrated, and rest until the feeling passes. back pain,Maintain proper posture, apply heat or cold packs, and do gentle stretching exercises. sore throat,Drink warm liquids, use throat lozenges, and consider gargling with warm salt water. dizziness,Rest in a cool and dark place, drink water, and avoid sudden movements. allergy,Avoid known allergens, keep windows closed during high pollen days, and consider antihistamines. constipation,Increase fiber intake with fruits and vegetables, drink plenty of water, and maintain an active lifestyle. insomnia,Establish a consistent sleep schedule, create a calming bedtime routine, and avoid screens before bed. - User
Provide me a medical data from github
- Assistant
I'm unable to access external websites, including GitHub, in real-time to provide you with a specific dataset directly from there. However, I can guide you on how to find and use a medical dataset from GitHub.
How to Find Medical Data on GitHub:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.