Spaces:
Runtime error
Runtime error
Moritz Stephan
commited on
Commit
·
2e744f0
1
Parent(s):
7835ab6
added demo code
Browse files- app.py +55 -4
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,7 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
def greet(name):
|
| 4 |
-
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import threading
|
| 4 |
+
from typing import Optional, List, Tuple
|
| 5 |
+
|
| 6 |
import gradio as gr
|
| 7 |
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
ENDPOINT_URL = "https://austrian-code-wizard--metarlaif-web-dev.modal.run"
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def get_feedback_options() -> List[Tuple[str, str]]:
|
| 13 |
+
args = {
|
| 14 |
+
"C3PO_API_KEY": os.environ.get("C3PO_API_KEY"),
|
| 15 |
+
}
|
| 16 |
+
response = requests.post(f"{ENDPOINT_URL}/list_adapters", json=args)
|
| 17 |
+
data = response.json()["adapters"]
|
| 18 |
+
return [
|
| 19 |
+
(adapter["feedback_name"], adapter["feedback_id"])
|
| 20 |
+
for adapter in data]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def get_completion(prompt: str, adapter: Optional[str] = None) -> str:
|
| 24 |
+
args = {
|
| 25 |
+
"C3PO_API_KEY": os.environ.get("C3PO_API_KEY"),
|
| 26 |
+
"prompt": prompt,
|
| 27 |
+
"adapter": adapter,
|
| 28 |
+
}
|
| 29 |
+
response = requests.post(f"{ENDPOINT_URL}/completion", json=args)
|
| 30 |
+
data = response.json()
|
| 31 |
+
return data["response"]
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def warmup(*args):
|
| 35 |
+
args = {
|
| 36 |
+
"C3PO_API_KEY": os.environ.get("C3PO_API_KEY"),
|
| 37 |
+
}
|
| 38 |
+
# Warmup the server but don't wait for the response
|
| 39 |
+
threading.Thread(target=requests.post, args=(f"{ENDPOINT_URL}/warmup"), kwargs={"json": args}, daemon=True).start()
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
demo = gr.Interface(
|
| 43 |
+
get_completion,
|
| 44 |
+
[
|
| 45 |
+
gr.Textbox(
|
| 46 |
+
placeholder="Enter a prompt...", label="Prompt"
|
| 47 |
+
),
|
| 48 |
+
gr.Dropdown(
|
| 49 |
+
label="Feedback", info="Will add the adapter for the respective feedback to the model."
|
| 50 |
+
)
|
| 51 |
+
],
|
| 52 |
+
"text",
|
| 53 |
+
concurrency_limit=8
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
demo.queue(max_size=32)
|
| 58 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
requests==2.31.0
|