Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,47 @@ import gradio as gr
|
|
2 |
import os
|
3 |
from huggingface_hub import login
|
4 |
|
5 |
-
# api_key = os.getenv('llama3token')
|
6 |
-
# login(api_key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
HF_TOKEN = os.getenv('llama3token')
|
9 |
-
login(HF_TOKEN)
|
10 |
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
|
|
2 |
import os
|
3 |
from huggingface_hub import login
|
4 |
|
5 |
+
# # api_key = os.getenv('llama3token')
|
6 |
+
# # login(api_key)
|
7 |
+
|
8 |
+
# HF_TOKEN = os.getenv('llama3token')
|
9 |
+
# login(HF_TOKEN)
|
10 |
+
|
11 |
+
# demo = gr.load("deepseek-ai/DeepSeek-R1-Distill-Llama-8B", src="models")
|
12 |
+
# demo.launch()
|
13 |
+
|
14 |
+
|
15 |
+
import streamlit as st
|
16 |
+
import requests
|
17 |
+
|
18 |
+
# Hugging Face API URL
|
19 |
+
API_URL = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-R1-Distill-Llama-8B"
|
20 |
|
21 |
HF_TOKEN = os.getenv('llama3token')
|
|
|
22 |
|
23 |
+
|
24 |
+
# Function to query the Hugging Face API
|
25 |
+
def query(payload):
|
26 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
27 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
28 |
+
return response.json()
|
29 |
+
|
30 |
+
# Streamlit app
|
31 |
+
st.title("DeepSeek-R1-Distill-Qwen-32B Chatbot")
|
32 |
+
|
33 |
+
# Input text box
|
34 |
+
user_input = st.text_input("Enter your message:")
|
35 |
+
|
36 |
+
if user_input:
|
37 |
+
# Query the Hugging Face API with the user input
|
38 |
+
payload = {"inputs": user_input}
|
39 |
+
output = query(payload)
|
40 |
+
|
41 |
+
# Display the output
|
42 |
+
if isinstance(output, list) and len(output) > 0 and 'generated_text' in output[0]:
|
43 |
+
st.write("Response:")
|
44 |
+
st.write(output[0]['generated_text'])
|
45 |
+
else:
|
46 |
+
st.write("Error: Unable to generate a response. Please try again.")
|
47 |
+
|
48 |
|