sureshnam9 commited on
Commit
7e0b9e8
·
verified ·
1 Parent(s): 66ac57b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -12
app.py CHANGED
@@ -1,25 +1,64 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
2
  import requests
3
  import json
4
 
 
 
 
 
 
 
 
5
  URL = "198.175.88.52"
 
6
  myport = "8080"
7
- g2url = f"http://{URL}:{myport}/generate"
8
-
9
- prompt="Why is the sky purple"
10
- #build_curl_prompt="curl ${g2url} -X POST -d '{\"inputs\":\"${prompt}\",\"parameters\":{\"max_new_tokens\":32}}' -H 'Content-Type: application/json'"
11
 
12
- url_input = gr.Textbox(label="URL", value=g2url, visible=True)
13
- prompt_input = gr.Textbox(label="Prompt", value=prompt, visible=True)
14
- outputs = gr.Textbox(label="Generated Text")
15
 
 
16
  def text_gen(url, prompt):
17
- resp = requests.post(url, data=json.dumps(prompt))
18
- return resp.text
 
 
 
 
 
19
 
20
  demo = gr.Interface(
21
  fn=text_gen,
22
- inputs=[url_input, prompt_input],
23
- outputs=[outputs])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- demo.launch(share=True)
 
1
  import gradio as gr
2
+ import os
3
+ import argparse
4
+ import concurrent.futures
5
+ import json
6
+ import logging
7
+ import math
8
+ import time
9
+ from itertools import cycle
10
+ from pathlib import Path
11
+ from langchain_community.llms import HuggingFaceEndpoint
12
  import requests
13
  import json
14
 
15
+ import torch
16
+ import gradio as gr
17
+ from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
18
+
19
+
20
+ #url = os.environ["TGI_GAUDI_ENDPOINT_URL"]
21
+ #myport = os.environ["myport"]
22
  URL = "198.175.88.52"
23
+ #URL = "100.81.119.213"
24
  myport = "8080"
 
 
 
 
25
 
26
+ gaudi_device_url = f"http://{URL}:{myport}/generate"
 
 
27
 
28
+ # This assumes that TGI is running on Gaudi so we don't need to define the pipeline here. It's like we're sending a curl command
29
  def text_gen(url, prompt):
30
+ resp = requests.post(url, prompt=json.dumps(prompt))
31
+ return resp
32
+
33
+ def text_gen_cpu(prompt):
34
+ pipe = pipeline(task="text-generation", model="gpt2", tokenizer="gpt2", device="cpu", torch_dtype=torch.bfloat16)
35
+ result = pipe(prompt, max_length=100, num_return_sequences=1)
36
+ return result
37
 
38
  demo = gr.Interface(
39
  fn=text_gen,
40
+ inputs=[gaudi_device_url, "text"],
41
+ outputs=["text"],
42
+
43
+ )
44
+
45
+ demo.launch()
46
+
47
+
48
+ #url = gr.Textbox(label='url', value=URL, visible=False)
49
+
50
+ # This is some demo code for using the
51
+ #llm = HuggingFaceEndpoint(
52
+ # endpoint_url=url,
53
+ # max_new_tokens=1024,
54
+ # top_k=10,
55
+ # top_p=0.95,
56
+ # typical_p=0.95,
57
+ # temperature=0.01,
58
+ # repetition_penalty=1.03,
59
+ # streaming=True,
60
+ # )
61
+
62
+ #result = llm.invoke("Why is the sky blue?")
63
+ #print(result)
64