Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
logging.info(f"
|
| 12 |
-
return output
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|