ferferefer commited on
Commit
4e9231e
·
verified ·
1 Parent(s): a0231a2

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -54
app.py DELETED
@@ -1,54 +0,0 @@
1
- import streamlit as st
2
- import requests
3
- import os
4
-
5
- # Initialize chat history in session state
6
- if 'chat_history' not in st.session_state:
7
- st.session_state.chat_history = []
8
-
9
- st.title("DeepSeek-V3 Chatbot")
10
-
11
- # Display chat messages from history
12
- for message in st.session_state.chat_history:
13
- st.write(f"**{message['role'].capitalize()}:** {message['content']}")
14
-
15
- # Input for user message
16
- user_input = st.text_input("You:", key="user_input")
17
-
18
- if st.button("Send"):
19
- if user_input:
20
- # Append user message to chat history
21
- st.session_state.chat_history.append({"role": "user", "content": user_input})
22
-
23
- # Prepare payload for Hugging Face Inference API
24
- payload = {
25
- "inputs": {
26
- "past_user_inputs": [msg['content'] for msg in st.session_state.chat_history if msg['role'] == 'user'],
27
- "generated_responses": [msg['content'] for msg in st.session_state.chat_history if msg['role'] == 'assistant'],
28
- "text": user_input
29
- }
30
- }
31
-
32
- # Fetch API token from environment variables
33
- API_TOKEN = os.getenv("API_TOKEN")
34
- if not API_TOKEN:
35
- st.error("API_TOKEN not found. Please set it as an environment variable.")
36
- else:
37
- api_url = "https://api-inference.huggingface.co/models/deepseek-ai/DeepSeek-V3"
38
- headers = {"Authorization": f"Bearer {API_TOKEN}"}
39
-
40
- # Send request to Hugging Face Inference API
41
- response = requests.post(api_url, headers=headers, json=payload)
42
-
43
- if response.status_code == 200:
44
- assistant_reply = response.json().get('generated_text', '')
45
- # Append assistant's reply to chat history
46
- st.session_state.chat_history.append({"role": "assistant", "content": assistant_reply})
47
- st.write(f"**Assistant:** {assistant_reply}")
48
- else:
49
- st.error("Error: Unable to get response from DeepSeek-V3 model.")
50
- else:
51
- st.warning("Please enter a message.")
52
-
53
- if st.button("Clear Chat"):
54
- st.session_state.chat_history = []