Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import http.client
|
| 3 |
+
|
| 4 |
+
url = os.environ['cnvrg_url']
|
| 5 |
+
token = os.environ['cnvrg_token']
|
| 6 |
+
|
| 7 |
+
def generate_output(prompt,maxtokens=20):
|
| 8 |
+
payload = f"{maxtokens}#{prompt}"
|
| 9 |
+
conn = http.client.HTTPSConnection(url, 443)
|
| 10 |
+
payload = f"{\"input_params\": \"{payload}\"}"
|
| 11 |
+
headers = {
|
| 12 |
+
'Cnvrg-Api-Key': token,
|
| 13 |
+
'Content-Type': "application/json"
|
| 14 |
+
}
|
| 15 |
+
conn.request("POST", "/api/v1/endpoints/nkjpkfaw14saekgsvudy", payload, headers)
|
| 16 |
+
res = conn.getresponse()
|
| 17 |
+
data = res.read()
|
| 18 |
+
return data.decode("utf-8")
|
| 19 |
+
|
| 20 |
+
input_text = gr.inputs.Textbox(label="Enter Prompt")
|
| 21 |
+
output_text = gr.outputs.Textbox(label="Output")
|
| 22 |
+
|
| 23 |
+
title = "Cnvrg Endpoint"
|
| 24 |
+
description = "Interact with the endpoint - Falcon 7B (Instruct)"
|
| 25 |
+
|
| 26 |
+
gr.Interface(fn=generate_output, inputs=input_text, outputs=output_text, title=title, description=description).launch()
|