asthaa30 commited on
Commit
aa8b9f3
·
verified ·
1 Parent(s): 3c28e17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -1,15 +1,19 @@
1
-
2
  # app.py
3
 
4
  import gradio as gr
5
- from transformers import AutoTokenizer, AutoModelForCausalLM
6
  from groq import Groq
7
  import os
8
  from huggingface_hub import login
 
 
 
 
9
 
10
  # Initialize Groq API client
11
  try:
12
  client = Groq(api_key=os.environ["GROQ_API_KEY"])
 
13
  except KeyError:
14
  raise ValueError("GROQ_API_KEY environment variable not set.")
15
 
@@ -22,19 +26,12 @@ if hf_token is None:
22
  login(token=hf_token)
23
 
24
  # Model identifier for Groq API (you can replace it with your HF model if needed)
25
- # Model identifier
26
  model_name = "asthaa30/l3.1"
27
 
28
- # Load tokenizer and model directly
29
- try:
30
- tokenizer = AutoTokenizer.from_pretrained(model_name)
31
- model = AutoModelForCausalLM.from_pretrained(model_name)
32
- except Exception as e:
33
- raise ValueError(f"Failed to load model or tokenizer: {e}")
34
-
35
  # Load tokenizer (model will be accessed via Groq API)
36
  try:
37
- tokenizer = AutoTokenizer.from_pretrained(model_name, token=hf_token)
 
38
  except Exception as e:
39
  raise ValueError(f"Failed to load tokenizer: {e}")
40
 
@@ -66,8 +63,9 @@ def respond(
66
  top_p=top_p,
67
  )
68
  assistant_message = response.choices[0].message['content']
 
69
  except Exception as e:
70
- print(f"An error occurred while getting model response: {str(e)}")
71
  assistant_message = "An error occurred. Please try again later."
72
 
73
  return assistant_message
@@ -75,7 +73,7 @@ def respond(
75
  demo = gr.ChatInterface(
76
  respond,
77
  additional_inputs=[
78
- gr.Textbox(value="You are an experienced maritime legal assistant.", label="System message"),
79
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
80
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
81
  gr.Slider(
@@ -91,4 +89,4 @@ demo = gr.ChatInterface(
91
  )
92
 
93
  if __name__ == "__main__":
94
- demo.launch()
 
 
1
  # app.py
2
 
3
  import gradio as gr
4
+ from transformers import AutoTokenizer
5
  from groq import Groq
6
  import os
7
  from huggingface_hub import login
8
+ import logging
9
+
10
+ # Setup logging
11
+ logging.basicConfig(level=logging.DEBUG)
12
 
13
  # Initialize Groq API client
14
  try:
15
  client = Groq(api_key=os.environ["GROQ_API_KEY"])
16
+ logging.info("Groq API client initialized.")
17
  except KeyError:
18
  raise ValueError("GROQ_API_KEY environment variable not set.")
19
 
 
26
  login(token=hf_token)
27
 
28
  # Model identifier for Groq API (you can replace it with your HF model if needed)
 
29
  model_name = "asthaa30/l3.1"
30
 
 
 
 
 
 
 
 
31
  # Load tokenizer (model will be accessed via Groq API)
32
  try:
33
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
34
+ logging.info(f"Tokenizer for model '{model_name}' loaded successfully.")
35
  except Exception as e:
36
  raise ValueError(f"Failed to load tokenizer: {e}")
37
 
 
63
  top_p=top_p,
64
  )
65
  assistant_message = response.choices[0].message['content']
66
+ logging.info(f"Received response from model: {assistant_message}")
67
  except Exception as e:
68
+ logging.error(f"An error occurred while getting model response: {str(e)}")
69
  assistant_message = "An error occurred. Please try again later."
70
 
71
  return assistant_message
 
73
  demo = gr.ChatInterface(
74
  respond,
75
  additional_inputs=[
76
+ gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
77
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
78
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
79
  gr.Slider(
 
89
  )
90
 
91
  if __name__ == "__main__":
92
+ demo.launch(share=True)