Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,7 +151,7 @@ def readitaloud(result):
|
|
| 151 |
components.html(documentHTML5, width=800, height=300)
|
| 152 |
#return result
|
| 153 |
|
| 154 |
-
def
|
| 155 |
# API_URL = 'https://qe55p8afio98s0u3.us-east-1.aws.endpoints.huggingface.cloud' # Dr Llama
|
| 156 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf" # HF model for Llama 7B
|
| 157 |
#API_KEY = os.getenv('API_KEY')
|
|
@@ -169,15 +169,18 @@ def chat_with_model_llama(prompt, document_section, model_choice='Llama-2-7b-cha
|
|
| 169 |
conversation.append({'role': 'user', 'content': prompt})
|
| 170 |
if len(document_section)>0:
|
| 171 |
conversation.append({'role': 'assistant', 'content': document_section})
|
|
|
|
| 172 |
start_time = time.time()
|
| 173 |
st.write('starting at ', start_time)
|
| 174 |
report = []
|
| 175 |
res_box = st.empty()
|
|
|
|
| 176 |
collected_chunks = []
|
| 177 |
collected_messages = []
|
| 178 |
|
| 179 |
endpoint_url = API_URL
|
| 180 |
hf_token = API_KEY
|
|
|
|
| 181 |
client = InferenceClient(endpoint_url, token=hf_token)
|
| 182 |
gen_kwargs = dict(
|
| 183 |
max_new_tokens=512,
|
|
@@ -185,8 +188,8 @@ def chat_with_model_llama(prompt, document_section, model_choice='Llama-2-7b-cha
|
|
| 185 |
top_p=0.9,
|
| 186 |
temperature=0.2,
|
| 187 |
repetition_penalty=1.02,
|
| 188 |
-
stop_sequences=["\nUser:", "<|endoftext|>", "</s>"]
|
| 189 |
-
|
| 190 |
stream = client.text_generation(prompt, stream=True, details=True, **gen_kwargs)
|
| 191 |
report=[]
|
| 192 |
res_box = st.empty()
|
|
@@ -218,7 +221,7 @@ def chat_with_model_llama(prompt, document_section, model_choice='Llama-2-7b-cha
|
|
| 218 |
|
| 219 |
|
| 220 |
# Chat and Chat with files
|
| 221 |
-
def
|
| 222 |
model = model_choice
|
| 223 |
conversation = [{'role': 'system', 'content': 'You are a python script writer.'}]
|
| 224 |
conversation.append({'role': 'user', 'content': prompt})
|
|
|
|
| 151 |
components.html(documentHTML5, width=800, height=300)
|
| 152 |
#return result
|
| 153 |
|
| 154 |
+
def chat_with_model(prompt, document_section, model_choice='Llama-2-7b-chat-hf'):
|
| 155 |
# API_URL = 'https://qe55p8afio98s0u3.us-east-1.aws.endpoints.huggingface.cloud' # Dr Llama
|
| 156 |
API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf" # HF model for Llama 7B
|
| 157 |
#API_KEY = os.getenv('API_KEY')
|
|
|
|
| 169 |
conversation.append({'role': 'user', 'content': prompt})
|
| 170 |
if len(document_section)>0:
|
| 171 |
conversation.append({'role': 'assistant', 'content': document_section})
|
| 172 |
+
|
| 173 |
start_time = time.time()
|
| 174 |
st.write('starting at ', start_time)
|
| 175 |
report = []
|
| 176 |
res_box = st.empty()
|
| 177 |
+
|
| 178 |
collected_chunks = []
|
| 179 |
collected_messages = []
|
| 180 |
|
| 181 |
endpoint_url = API_URL
|
| 182 |
hf_token = API_KEY
|
| 183 |
+
|
| 184 |
client = InferenceClient(endpoint_url, token=hf_token)
|
| 185 |
gen_kwargs = dict(
|
| 186 |
max_new_tokens=512,
|
|
|
|
| 188 |
top_p=0.9,
|
| 189 |
temperature=0.2,
|
| 190 |
repetition_penalty=1.02,
|
| 191 |
+
stop_sequences=["\nUser:", "<|endoftext|>", "</s>"] )
|
| 192 |
+
|
| 193 |
stream = client.text_generation(prompt, stream=True, details=True, **gen_kwargs)
|
| 194 |
report=[]
|
| 195 |
res_box = st.empty()
|
|
|
|
| 221 |
|
| 222 |
|
| 223 |
# Chat and Chat with files
|
| 224 |
+
def chat_with_model2(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
| 225 |
model = model_choice
|
| 226 |
conversation = [{'role': 'system', 'content': 'You are a python script writer.'}]
|
| 227 |
conversation.append({'role': 'user', 'content': prompt})
|