Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,29 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
demo.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# Load the model and tokenizer
|
| 5 |
+
model_name = "deepseek-ai/deepseek-coder-1.3b-instruct"
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=True)
|
| 7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=True)
|
| 8 |
+
|
| 9 |
+
# Define the response function
|
| 10 |
+
def respond(query):
|
| 11 |
+
prompt = f"[INST] {query} [/INST]"
|
| 12 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 13 |
+
outputs = model.generate(
|
| 14 |
+
**inputs,
|
| 15 |
+
max_new_tokens=50, # Adjust based on resource constraints
|
| 16 |
+
pad_token_id=tokenizer.eos_token_id
|
| 17 |
+
)
|
| 18 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 19 |
+
return response
|
| 20 |
+
|
| 21 |
+
# Create the Gradio interface
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("# Deepseek Coder Chatbot")
|
| 24 |
+
query_input = gr.Textbox(label="Ask me anything...")
|
| 25 |
+
output = gr.Textbox(label="Response")
|
| 26 |
+
submit_button = gr.Button("Submit")
|
| 27 |
+
submit_button.click(respond, inputs=query_input, outputs=output)
|
| 28 |
+
|
| 29 |
demo.launch()
|