bstraehle commited on
Commit
370c03f
1 Parent(s): b4f1b82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -32,14 +32,16 @@ def wandb_log(prompt, completion):
32
  def invoke(prompt):
33
  if (prompt == ""):
34
  raise gr.Error("Prompt is required.")
 
35
  completion = ""
 
36
  try:
37
- body = json.dumps({"prompt": "\n\nHuman: " + prompt + "\n\nAssistant: ",
38
  "max_tokens_to_sample": config["max_tokens_to_sample"],
39
  "temperature": config["temperature"],
40
  "top_k": config["top_k"],
41
  "top_p": config["top_p"],
42
- "stop_sequences": ["\n\nHuman: "]
43
  })
44
  modelId = config["model"]
45
  accept = "application/json"
@@ -52,15 +54,15 @@ def invoke(prompt):
52
  raise gr.Error(e)
53
  finally:
54
  wandb_log(prompt, completion)
 
55
  return completion
56
- #return "🛑 Execution is commented out. To view the source code see https://huggingface.co/spaces/bstraehle/amazon-bedrock-llm/tree/main."
57
 
58
  description = """<a href='https://www.gradio.app/'>Gradio</a> UI using <a href='https://aws.amazon.com/bedrock/'>Amazon Bedrock</a> API
59
  with <a href='https://www.anthropic.com/'>Anthropic</a> Claude 2 foundation model.
60
  RAG evaluation via <a href='https://wandb.ai/bstraehle'>Weights & Biases</a>."""
61
 
62
  gr.close_all()
63
- demo = gr.Interface(fn=invoke,
64
  inputs = [gr.Textbox(label = "Prompt", lines = 1)],
65
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
66
  title = "Generative AI - LLM",
 
32
  def invoke(prompt):
33
  if (prompt == ""):
34
  raise gr.Error("Prompt is required.")
35
+
36
  completion = ""
37
+
38
  try:
39
+ body = json.dumps({"prompt": "Human: " + prompt + "Assistant: ",
40
  "max_tokens_to_sample": config["max_tokens_to_sample"],
41
  "temperature": config["temperature"],
42
  "top_k": config["top_k"],
43
  "top_p": config["top_p"],
44
+ "stop_sequences": ["Human: "]
45
  })
46
  modelId = config["model"]
47
  accept = "application/json"
 
54
  raise gr.Error(e)
55
  finally:
56
  wandb_log(prompt, completion)
57
+
58
  return completion
 
59
 
60
  description = """<a href='https://www.gradio.app/'>Gradio</a> UI using <a href='https://aws.amazon.com/bedrock/'>Amazon Bedrock</a> API
61
  with <a href='https://www.anthropic.com/'>Anthropic</a> Claude 2 foundation model.
62
  RAG evaluation via <a href='https://wandb.ai/bstraehle'>Weights & Biases</a>."""
63
 
64
  gr.close_all()
65
+ demo = gr.Interface(fn = invoke,
66
  inputs = [gr.Textbox(label = "Prompt", lines = 1)],
67
  outputs = [gr.Textbox(label = "Completion", lines = 1)],
68
  title = "Generative AI - LLM",