Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,68 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
-
import argparse
|
4 |
-
import concurrent.futures
|
5 |
-
import json
|
6 |
import requests
|
7 |
-
import
|
8 |
-
import math
|
9 |
-
import time
|
10 |
-
from itertools import cycle
|
11 |
-
from pathlib import Path
|
12 |
-
from langchain_community.llms import HuggingFaceEndpoint
|
13 |
-
|
14 |
-
import torch
|
15 |
-
import gradio as gr
|
16 |
-
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
|
17 |
-
|
18 |
|
19 |
-
#url = os.environ["TGI_GAUDI_ENDPOINT_URL"]
|
20 |
-
#myport = os.environ["myport"]
|
21 |
URL = "198.175.88.52"
|
22 |
-
#URL = "100.81.119.213"
|
23 |
myport = "8080"
|
|
|
24 |
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
def
|
33 |
-
|
34 |
-
result = pipe(prompt, max_length=100, num_return_sequences=1)
|
35 |
-
return result
|
36 |
|
37 |
demo = gr.Interface(
|
38 |
fn=text_gen,
|
39 |
-
|
40 |
-
outputs=[
|
41 |
-
|
42 |
-
)
|
43 |
-
|
44 |
-
demo.launch()
|
45 |
-
|
46 |
-
|
47 |
-
#url = gr.Textbox(label='url', value=URL, visible=False)
|
48 |
-
|
49 |
-
# This is some demo code for using the
|
50 |
-
#llm = HuggingFaceEndpoint(
|
51 |
-
# endpoint_url=url,
|
52 |
-
# max_new_tokens=1024,
|
53 |
-
# top_k=10,
|
54 |
-
# top_p=0.95,
|
55 |
-
# typical_p=0.95,
|
56 |
-
# temperature=0.01,
|
57 |
-
# repetition_penalty=1.03,
|
58 |
-
# streaming=True,
|
59 |
-
# )
|
60 |
-
|
61 |
-
#result = llm.invoke("Why is the sky blue?")
|
62 |
-
#print(result)
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
#result = llm.invoke("Why is the sky blue?")
|
67 |
-
#print(result)
|
68 |
|
|
|
|
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 |
+
resp = requests.post(url, data=json.dumps(prompt))
|
16 |
|
17 |
+
def text_gen(url, 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()
|