Tonic commited on
Commit
56ece3e
1 Parent(s): 9de6abb

Update maker.py

Browse files
Files changed (1) hide show
  1. maker.py +28 -18
maker.py CHANGED
@@ -3,6 +3,7 @@ import requests
3
  import json
4
  import huggingface_hub
5
  from huggingface_hub import HfApi
 
6
  import os
7
 
8
  HF_TOKEN = os.environ["HF_TOKEN"]
@@ -70,28 +71,37 @@ def post_request_beta(payload):
70
 
71
 
72
  def predict_beta(message, chatbot=[], system_prompt=system_prompt):
73
- input_prompt = build_input_prompt(message, chatbot, system_prompt)
74
- data = {
75
- "inputs": input_prompt
76
- }
77
 
78
  try:
79
- response_data = post_request_beta(data)
80
- json_obj = response_data[0]
81
-
82
- if 'generated_text' in json_obj and len(json_obj['generated_text']) > 0:
83
- bot_message = json_obj['generated_text']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  return bot_message
85
- elif 'error' in json_obj:
86
- raise gr.Error(json_obj['error'] + ' Please refresh and try again with smaller input prompt')
87
  else:
88
- warning_msg = f"Unexpected response: {json_obj}"
89
- raise gr.Error(warning_msg)
90
- except requests.HTTPError as e:
91
- error_msg = f"Request failed with status code {e.response.status_code}"
92
- raise gr.Error(error_msg)
93
- except json.JSONDecodeError as e:
94
- error_msg = f"Failed to decode response as JSON: {str(e)}"
95
  raise gr.Error(error_msg)
96
 
97
 
 
3
  import json
4
  import huggingface_hub
5
  from huggingface_hub import HfApi
6
+ from gradio_client import Client
7
  import os
8
 
9
  HF_TOKEN = os.environ["HF_TOKEN"]
 
71
 
72
 
73
  def predict_beta(message, chatbot=[], system_prompt=system_prompt):
74
+ client = Client(tulu)
 
 
 
75
 
76
  try:
77
+ # Adjust these parameters as needed
78
+ max_new_tokens = 880
79
+ temperature = 0.4
80
+ top_p = 0.9
81
+ repetition_penalty = 0.7
82
+ advanced = True
83
+
84
+ # Making the prediction
85
+ result = client.predict(
86
+ message, # Your Message
87
+ system_prompt, # Optional Tulu Assistant Message (can adjust if needed)
88
+ max_new_tokens,
89
+ temperature,
90
+ top_p,
91
+ repetition_penalty,
92
+ advanced,
93
+ fn_index=0
94
+ )
95
+
96
+ # Extracting the response
97
+ if result is not None and len(result) > 0:
98
+ bot_message = result[0] # Assuming the response is in the first element
99
  return bot_message
 
 
100
  else:
101
+ raise gr.Error("No response received from the model.")
102
+
103
+ except Exception as e:
104
+ error_msg = f"An error occurred: {str(e)}"
 
 
 
105
  raise gr.Error(error_msg)
106
 
107