debisoft commited on
Commit
7d68ac7
1 Parent(s): 2c7ad90

prompt only

Browse files
Files changed (1) hide show
  1. app.py +30 -41
app.py CHANGED
@@ -1,53 +1,42 @@
 
 
 
1
  import os
2
- import re
3
- from datetime import datetime
4
  import gradio as gr
5
  import json
6
  from dotenv import load_dotenv, find_dotenv
7
  _ = load_dotenv(find_dotenv())
8
 
9
- from training.consts import DEFAULT_INPUT_MODEL, SUGGESTED_INPUT_MODELS
10
- from training.trainer import load_training_dataset, load_tokenizer
11
- from training.generate import generate_response, load_model_tokenizer_for_generate
12
 
13
- gpu_family = "a100"
14
-
15
- model_dir = "model"
16
-
17
- model, tokenizer = load_model_tokenizer_for_generate(model_dir)
18
-
19
- def get_completion(prompt, model_name="dolly-v0-70m"):
20
- # Examples from https://www.databricks.com/blog/2023/03/24/hello-dolly-democratizing-magic-chatgpt-open-models.html
21
- instructions = [prompt]
22
- # set some additional pipeline args
23
- pipeline_kwargs = {'torch_dtype': "auto"}
24
- #if gpu_family == "v100":
25
- #pipeline_kwargs['torch_dtype'] = "float16"
26
- #elif gpu_family == "a10" or gpu_family == "a100":
27
- #pipeline_kwargs['torch_dtype'] = "bfloat16"
28
-
29
- pipeline_kwargs['max_new_tokens'] = 100
30
- #pipeline_kwargs['temperature'] = float("inf")
31
- #pipeline_kwargs['top_k'] = 1
32
- pipeline_kwargs['top_p'] = 0.01
33
-
34
- # Use the model to generate responses for each of the instructions above.
35
- for instruction in instructions:
36
- response = generate_response(instruction, model=model, tokenizer=tokenizer, **pipeline_kwargs)
37
- if response:
38
- print(f"Instruction: {instruction}\n\n{response}\n\n-----------\n")
39
- return response
40
 
41
  def greet(input):
42
- prompt = f"""
43
- Text: ```{input}```
44
- """
45
- response = get_completion(prompt)
46
- return response
47
-
48
- #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
49
- #iface.launch()
50
 
51
- #iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Text to find entities", lines=2)], outputs=[gr.HighlightedText(label="Text with entities")], title="NER with dslim/bert-base-NER", description="Find entities using the `dslim/bert-base-NER` model under the hood!", allow_flagging="never", examples=["My name is Andrew and I live in California", "My name is Poli and work at HuggingFace"])
52
  iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Prompt")], outputs="text")
53
  iface.launch()
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import requests
4
  import os
 
 
5
  import gradio as gr
6
  import json
7
  from dotenv import load_dotenv, find_dotenv
8
  _ = load_dotenv(find_dotenv())
9
 
 
 
 
10
 
11
+ databricks_token = os.getenv('DATABRICKS_TOKEN')
12
+ model_uri = "https://dbc-eb788f31-6c73.cloud.databricks.com/serving-endpoints/Mpt-7b-tester/invocations"
13
+
14
+ def score_model(model_uri, databricks_token, prompt):
15
+ dataset=pd.DataFrame({
16
+ "prompt":[prompt],
17
+ "temperature": [0.5],
18
+ "max_tokens": [1500]})
19
+ headers = {
20
+ "Authorization": f"Bearer {databricks_token}",
21
+ "Content-Type": "application/json",
22
+ }
23
+ ds_dict = {'dataframe_split': dataset.to_dict(orient='split')} if isinstance(dataset, pd.DataFrame) else create_tf_serving_json(dataset)
24
+ data_json = json.dumps(ds_dict, allow_nan=True)
25
+ print("***ds_dict: ")
26
+ print(ds_dict)
27
+ print("***data_json: ")
28
+ print(data_json)
29
+ response = requests.request(method='POST', headers=headers, url=model_uri, data=data_json)
30
+ if response.status_code != 200:
31
+ raise Exception(f"Request failed with status {response.status_code}, {response.text}")
32
+ return response.json()
33
+
34
+ def get_completion(prompt):
35
+ return score_model(model_uri, databricks_token, prompt)
 
 
36
 
37
  def greet(input):
38
+ response = get_completion(input)
39
+ return json.dumps(response)
 
 
 
 
 
 
40
 
 
41
  iface = gr.Interface(fn=greet, inputs=[gr.Textbox(label="Prompt")], outputs="text")
42
  iface.launch()