AEUPH commited on
Commit
ceb530c
·
verified ·
1 Parent(s): a36e220

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -9,12 +9,10 @@ from urllib.parse import unquote
9
  # Define the functions as provided in the original script
10
 
11
  def filter_text_and_preserve_emojis(text):
12
- # Pattern unchanged from original code
13
  pattern = re.compile(r'[a-zA-Z0-9\s.,?!\'"]|[\U0001F600-\U0001F64F\U0001F300-\U0001F5FF\U0001F680-\U0001F6FF\U0001F700-\U0001F77F\U0001F780-\U0001F7FF\U0001F800-\U0001F8FF\U0001F900-\U0001F9FF\U0001FA00-\U0001FA6F\U0001FA70-\U0001FAFF\U00002702-\U000027B0\U000024C2-\U0001F251]+')
14
  return ''.join(pattern.findall(text))
15
 
16
  def chatbot_api(input_text):
17
- # The setup for API call remains largely unchanged
18
  url = "https://chat.tune.app/api/chat/completions"
19
  decoded_text = unquote(input_text)
20
  headers = {
@@ -24,10 +22,10 @@ def chatbot_api(input_text):
24
  data = {
25
  "temperature": 0.5,
26
  "messages": [
27
- {"role": "system", "content": "System setup text here."}, # Adjusted system message
28
  {"role": "user", "content": decoded_text}
29
  ],
30
- "model": "openhermes-2-5-m7b-8k", # Replace with your actual model name
31
  "stream": False,
32
  "max_tokens": 350
33
  }
@@ -38,8 +36,7 @@ def chatbot_api(input_text):
38
  filtered_response = filter_text_and_preserve_emojis(full_content)
39
  except (KeyError, IndexError):
40
  filtered_response = "Error: The expected response format has changed or is missing."
41
-
42
- # Instead of sending to Corrade, format for OpenAI Action Schema
43
  return {
44
  "actions": [
45
  {"type": "message", "text": filtered_response}
@@ -50,13 +47,19 @@ def chatbot_api(input_text):
50
 
51
  st.title("Chatbot Interface")
52
 
53
- # User text input
54
- user_input = st.text_input("Enter your text here:")
 
55
 
56
- # Button to trigger processing
57
- if st.button("Submit"):
58
- result = chatbot_api(user_input)
59
-
60
- # Displaying the result
61
  if result:
62
  st.json(result)
 
 
 
 
 
 
 
 
9
  # Define the functions as provided in the original script
10
 
11
  def filter_text_and_preserve_emojis(text):
 
12
  pattern = re.compile(r'[a-zA-Z0-9\s.,?!\'"]|[\U0001F600-\U0001F64F\U0001F300-\U0001F5FF\U0001F680-\U0001F6FF\U0001F700-\U0001F77F\U0001F780-\U0001F7FF\U0001F800-\U0001F8FF\U0001F900-\U0001F9FF\U0001FA00-\U0001FA6F\U0001FA70-\U0001FAFF\U00002702-\U000027B0\U000024C2-\U0001F251]+')
13
  return ''.join(pattern.findall(text))
14
 
15
  def chatbot_api(input_text):
 
16
  url = "https://chat.tune.app/api/chat/completions"
17
  decoded_text = unquote(input_text)
18
  headers = {
 
22
  data = {
23
  "temperature": 0.5,
24
  "messages": [
25
+ {"role": "system", "content": "System setup text here."},
26
  {"role": "user", "content": decoded_text}
27
  ],
28
+ "model": "openhermes-2-5-m7b-8k",
29
  "stream": False,
30
  "max_tokens": 350
31
  }
 
36
  filtered_response = filter_text_and_preserve_emojis(full_content)
37
  except (KeyError, IndexError):
38
  filtered_response = "Error: The expected response format has changed or is missing."
39
+
 
40
  return {
41
  "actions": [
42
  {"type": "message", "text": filtered_response}
 
47
 
48
  st.title("Chatbot Interface")
49
 
50
+ # Fetch the URL parameter
51
+ query_params = st.experimental_get_query_params()
52
+ auto_submit_text = query_params.get("input_text", [None])[0]
53
 
54
+ # Check if there's an input from URL parameter and auto-submit
55
+ if auto_submit_text is not None:
56
+ result = chatbot_api(auto_submit_text)
 
 
57
  if result:
58
  st.json(result)
59
+ else:
60
+ # Manual input
61
+ user_input = st.text_input("Enter your text here:")
62
+ if st.button("Submit"):
63
+ result = chatbot_api(user_input)
64
+ if result:
65
+ st.json(result)