Muhammadidrees commited on
Commit
c33a7b6
·
verified ·
1 Parent(s): 0329fd9

Update DocBrain.py

Browse files
Files changed (1) hide show
  1. DocBrain.py +6 -7
DocBrain.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
- from transformers import AutoProcessor, AutoModelForVision2Seq
3
  import torch
 
4
  from PaitentVoiceToText import record_and_transcribe # Your STT function
5
  from DocVoice import text_to_speech # Your TTS function
6
 
@@ -8,15 +8,15 @@ from DocVoice import text_to_speech # Your TTS function
8
  # 1️⃣ Load Model & Processor
9
  # -------------------
10
  def load_model():
11
- local_dir = r"C:\Users\JAY\Downloads\model\CHATDOCMODEL"
12
  device = "cuda" if torch.cuda.is_available() else "cpu"
13
  dtype = torch.float16 if device == "cuda" else torch.float32
14
 
15
- processor = AutoProcessor.from_pretrained(local_dir, trust_remote_code=True)
 
16
  model = AutoModelForVision2Seq.from_pretrained(
17
- local_dir,
18
- dtype=dtype,
19
- device_map=None
20
  )
21
  model.to(device)
22
  return processor, model, device
@@ -181,7 +181,6 @@ with gr.Blocks(title="ChatDOC", theme=gr.themes.Soft()) as demo:
181
 
182
  def mic_submit(history, question_count, assistant_responses):
183
  user_text = record_and_transcribe(duration=5)
184
- # Show user message immediately
185
  history.append([user_text, None])
186
  history, updated_history, question_count = process_message(user_text, history, question_count)
187
  assistant_responses = update_assistant_responses(history, assistant_responses)
 
1
  import gradio as gr
 
2
  import torch
3
+ from transformers import AutoProcessor, AutoModelForVision2Seq
4
  from PaitentVoiceToText import record_and_transcribe # Your STT function
5
  from DocVoice import text_to_speech # Your TTS function
6
 
 
8
  # 1️⃣ Load Model & Processor
9
  # -------------------
10
  def load_model():
 
11
  device = "cuda" if torch.cuda.is_available() else "cpu"
12
  dtype = torch.float16 if device == "cuda" else torch.float32
13
 
14
+ # Load directly from Hugging Face
15
+ processor = AutoProcessor.from_pretrained("Muhammadidrees/RaiyaChatDoc", trust_remote_code=True)
16
  model = AutoModelForVision2Seq.from_pretrained(
17
+ "Muhammadidrees/RaiyaChatDoc",
18
+ torch_dtype=dtype,
19
+ device_map="auto" # automatically assigns to GPU if available
20
  )
21
  model.to(device)
22
  return processor, model, device
 
181
 
182
  def mic_submit(history, question_count, assistant_responses):
183
  user_text = record_and_transcribe(duration=5)
 
184
  history.append([user_text, None])
185
  history, updated_history, question_count = process_message(user_text, history, question_count)
186
  assistant_responses = update_assistant_responses(history, assistant_responses)