gufett0 commited on
Commit
c611543
·
1 Parent(s): 3b72a1b

added new class

Browse files
Files changed (3) hide show
  1. app.py +9 -4
  2. backend.py +2 -2
  3. interface.py +8 -1
app.py CHANGED
@@ -5,11 +5,16 @@ import gradio as gr
5
 
6
  iface = gr.ChatInterface(
7
  fn=handle_query, # Query handling remains here
8
- title="PDF Information and Inference",
9
- description="Retrieval-Augmented Generation - Ask me anything about the content of the PDF.",
10
  )
11
 
 
 
 
 
 
12
 
13
  if __name__ == "__main__":
14
- progress=gr.Progress(track_tqdm=True)
15
- iface.launch(debug=True)
 
5
 
6
  iface = gr.ChatInterface(
7
  fn=handle_query, # Query handling remains here
8
+ title="Odi, la chatbot degli Osservatori",
9
+ description="Retrieval-Augmented Generation - Ask me anything about the research carried out at the Osservatori.",
10
  )
11
 
12
+ css = """
13
+ body {
14
+ background-color: #ADD8E6; /* Light blue background */
15
+ }
16
+ """
17
 
18
  if __name__ == "__main__":
19
+ progress = gr.Progress(track_tqdm=True)
20
+ iface.launch(debug=True, css=css)
backend.py CHANGED
@@ -20,14 +20,14 @@ login(huggingface_token)
20
 
21
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
22
 
23
- model_id = "google/gemma-2-2b-it"
24
  tokenizer = AutoTokenizer.from_pretrained(model_id)
25
  model = AutoModelForCausalLM.from_pretrained(
26
  model_id,
27
  device_map="auto", ## change this back to auto!!!
28
  torch_dtype= torch.bfloat16 if torch.cuda.is_available() else torch.float32,
29
  token=True)
30
- model.eval()
31
 
32
  #from accelerate import disk_offload
33
  #disk_offload(model=model, offload_dir="offload")
 
20
 
21
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
22
 
23
+ """model_id = "google/gemma-2-2b-it"
24
  tokenizer = AutoTokenizer.from_pretrained(model_id)
25
  model = AutoModelForCausalLM.from_pretrained(
26
  model_id,
27
  device_map="auto", ## change this back to auto!!!
28
  torch_dtype= torch.bfloat16 if torch.cuda.is_available() else torch.float32,
29
  token=True)
30
+ model.eval()"""
31
 
32
  #from accelerate import disk_offload
33
  #disk_offload(model=model, offload_dir="offload")
interface.py CHANGED
@@ -5,7 +5,7 @@ from typing import Any
5
  import torch
6
  from transformers import TextIteratorStreamer
7
  from threading import Thread
8
- from pydantic import Field
9
 
10
  # for transformers 2
11
  class GemmaLLMInterface(CustomLLM):
@@ -15,6 +15,13 @@ class GemmaLLMInterface(CustomLLM):
15
  tokenizer: Any = Field(default=None)
16
  model: Any = Field(default=None)
17
 
 
 
 
 
 
 
 
18
  def __init__(self, **data):
19
  super().__init__(**data)
20
  self.tokenizer = AutoTokenizer.from_pretrained(self.model_id)
 
5
  import torch
6
  from transformers import TextIteratorStreamer
7
  from threading import Thread
8
+ from pydantic import Field, field_validator
9
 
10
  # for transformers 2
11
  class GemmaLLMInterface(CustomLLM):
 
15
  tokenizer: Any = Field(default=None)
16
  model: Any = Field(default=None)
17
 
18
+ @field_validator('context_window', 'num_output', mode='before')
19
+ @classmethod
20
+ def ensure_integer(cls, v):
21
+ if isinstance(v, str):
22
+ return int(v)
23
+ return v
24
+
25
  def __init__(self, **data):
26
  super().__init__(**data)
27
  self.tokenizer = AutoTokenizer.from_pretrained(self.model_id)