lunarflu HF staff commited on
Commit
6ff1b24
·
verified ·
1 Parent(s): e13e868

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -1,19 +1,32 @@
1
  import gradio as gr
2
  import logging
 
3
 
4
  logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
5
 
6
- def wrapped_model(*args, **kwargs):
7
- logging.info(f"Input arguments: {args}")
8
- logging.info(f"Keyword arguments: {kwargs}")
 
9
 
10
- output = original_model(*args, **kwargs)
11
- logging.info(f"Output: {output}")
12
- return output
13
 
14
- interface = gr.load("models/deepseek-ai/DeepSeek-R1")
 
15
 
16
- original_model = interface.fn
17
- interface.fn = wrapped_model
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  interface.launch()
 
1
  import gradio as gr
2
  import logging
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
 
5
  logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
6
 
7
+ model_name = "deepseek-ai/DeepSeek-R1"
8
+ logging.info(f"Loading model: {model_name}")
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+ model = AutoModelForCausalLM.from_pretrained(model_name)
11
 
12
+ def wrapped_model(input_text):
13
+ logging.info(f"Input text: {input_text}")
 
14
 
15
+ inputs = tokenizer(input_text, return_tensors="pt")
16
+ logging.debug(f"Tokenized input: {inputs}")
17
 
18
+ outputs = model.generate(**inputs, max_length=512, num_return_sequences=1)
19
+ logging.debug(f"Model output tokens: {outputs}")
20
+
21
+ decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
22
+ logging.info(f"Decoded output: {decoded_output}")
23
+
24
+ return decoded_output
25
+
26
+ interface = gr.Interface(
27
+ fn=wrapped_model,
28
+ inputs=gr.Textbox(lines=2, label="Enter your prompt"),
29
+ outputs=gr.Textbox(label="Output")
30
+ )
31
 
32
  interface.launch()