soufyane commited on
Commit
22711eb
1 Parent(s): 64b1f7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -17
app.py CHANGED
@@ -1,35 +1,33 @@
1
- import gradio as gr
2
- from gtts import gTTS
3
- from io import BytesIO
4
- import IPython.display as ipd
5
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
 
 
 
 
 
6
 
7
  # Load your Hugging Face model and tokenizer
8
  model_name = "soufyane/gemma_data_science"
9
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
10
  tokenizer = AutoTokenizer.from_pretrained(model_name)
11
 
 
 
12
  def process_text_gemma(input_text):
13
- input_ids = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)["input_ids"]
14
- output_ids = model.generate(input_ids)
15
- response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
16
  return response
17
 
18
- def process_speech_gemma(audio):
19
- response = process_text_gemma(audio)
20
- tts = gTTS(text=response, lang='en')
21
- fp = BytesIO()
22
- tts.write_to_fp(fp)
23
- fp.seek(0)
24
- return ipd.Audio(fp.read(), autoplay=True)
25
 
26
  def main(input_text):
27
- return process_text_gemma(input_text[0]), process_speech_gemma(input_text[0])
28
 
29
  gr.Interface(
30
  fn=main,
31
  inputs=["text"],
32
- outputs=["text", "audio"],
33
  title="Gemma Data Science Model",
34
  description="This is a text-to-text model for data science tasks.",
35
  live=True
 
1
+ import keras_nlp
2
+ from keras_nlp.models import GemmaCausalLM
3
+ import warnings
4
+ warnings.filterwarnings('ignore')
5
+ import os
6
+
7
+ #set the envirenment
8
+ os.environ["KERAS_BACKEND"] = "jax" # Or "torch" or "tensorflow".
9
+
10
+ os.environ["XLA_PYTHON_CLIENT_MEM_FRACTION"]="1.00"
11
 
12
  # Load your Hugging Face model and tokenizer
13
  model_name = "soufyane/gemma_data_science"
14
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
15
  tokenizer = AutoTokenizer.from_pretrained(model_name)
16
 
17
+ model = keras_nlp.models.CausalLM.from_preset(f"hf://soufyane/gemma_data_science")
18
+
19
  def process_text_gemma(input_text):
20
+ response = model.generate(f"question: {input_text}", max_length=256)
 
 
21
  return response
22
 
 
 
 
 
 
 
 
23
 
24
  def main(input_text):
25
+ return process_text_gemma(input_text[0])
26
 
27
  gr.Interface(
28
  fn=main,
29
  inputs=["text"],
30
+ outputs=["text"],
31
  title="Gemma Data Science Model",
32
  description="This is a text-to-text model for data science tasks.",
33
  live=True