ahmfzui commited on
Commit
b3c91c6
·
verified ·
1 Parent(s): d4fd1b5

Upload 2 files

Browse files
Files changed (2) hide show
  1. edm.py +45 -0
  2. requirements.txt +8 -0
edm.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import InferenceClient
3
+ import streamlit as st
4
+
5
+ # Access your Hugging Face API token from the environment variable
6
+ api_token = os.getenv("HUGGINGFACEHUB_API_TOKEN")
7
+ if api_token is None:
8
+ st.error("Hugging Face API token is not set.")
9
+ else:
10
+ st.title("Tanya Gizi!")
11
+
12
+ # Initialize chat history if not already present
13
+ if 'messages' not in st.session_state:
14
+ st.session_state.messages = []
15
+
16
+ # Display chat history
17
+ for message in st.session_state.messages:
18
+ st.chat_message(message['role']).markdown(message['content'])
19
+
20
+ # Input area for the user
21
+ prompt = st.chat_input('Masukan pertanyaanmu di sini!')
22
+
23
+ # Process user input
24
+ if prompt:
25
+ st.chat_message('user').markdown(prompt)
26
+ st.session_state.messages.append({'role': 'user', 'content': prompt})
27
+
28
+ # Generate a response using InferenceClient
29
+ client = InferenceClient(
30
+ model="mistralai/Mistral-Large-Instruct-2407",
31
+ token=api_token
32
+ )
33
+
34
+ # Generating response
35
+ response = client.chat_completion(
36
+ messages=[{"role": "user", "content": prompt}],
37
+ max_tokens=100,
38
+ stream=False # Disable streaming as it's not supported
39
+ )
40
+
41
+ response_text = response['choices'][0]['message']['content']
42
+
43
+ # Display and store the assistant's response
44
+ st.chat_message('assistant').markdown(response_text)
45
+ st.session_state.messages.append({'role': 'assistant', 'content': response_text})
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ beautifulsoup4==4.12.3
2
+ filelock==3.15.4
3
+ huggingface_hub==0.23.4
4
+ kagglehub==0.2.8
5
+ pytz==2023.3
6
+ Requests==2.32.3
7
+ streamlit==1.36.0
8
+ urllib3==1.26.19