create app.py
#2
by
shibly100
- opened
app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Load model and tokenizer from Hugging Face directly
|
| 6 |
+
model_name = "deepseek-ai/deepseek-7b-instruct"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
| 9 |
+
|
| 10 |
+
# Create a simple chat function
|
| 11 |
+
def chat_function(prompt):
|
| 12 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 13 |
+
outputs = model.generate(**inputs, max_length=200)
|
| 14 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
+
return response
|
| 16 |
+
|
| 17 |
+
# Build a simple Gradio interface
|
| 18 |
+
iface = gr.Interface(fn=chat_function, inputs="text", outputs="text")
|
| 19 |
+
iface.launch()
|