Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
# Load model & tokenizer
|
| 8 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
| 9 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 10 |
-
MODEL_NAME,
|
| 11 |
-
torch_dtype=torch.float16,
|
| 12 |
-
device_map="auto" # Uses available GPU/CPU
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
# Create text generation pipeline
|
| 16 |
-
pipe = TextGenerationPipeline(model=model, tokenizer=tokenizer)
|
| 17 |
-
|
| 18 |
-
# Define Gradio interface
|
| 19 |
def chat(prompt):
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="DeepSeek
|
| 24 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
HF_API_KEY = os.getenv('TOKEN')
|
| 6 |
+
MODEL_NAME = "deepseek-ai/deepseek-llm-7b-chat"
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def chat(prompt):
|
| 9 |
+
response = requests.post(
|
| 10 |
+
f"https://api-inference.huggingface.co/models/{MODEL_NAME}",
|
| 11 |
+
headers={"Authorization": f"Bearer {HF_API_KEY}"},
|
| 12 |
+
json={"inputs": prompt}
|
| 13 |
+
)
|
| 14 |
+
return response.json()[0]["generated_text"]
|
| 15 |
|
| 16 |
+
iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="DeepSeek API Chatbot")
|
| 17 |
iface.launch()
|