Spaces:
Sleeping
Sleeping
Patrick Rathje
commited on
Commit
·
1735827
1
Parent(s):
57c34dd
working huggingface inference endpoint
Browse files
app.py
CHANGED
|
@@ -7,21 +7,30 @@ import subprocess
|
|
| 7 |
from threading import Timer
|
| 8 |
from functools import partial
|
| 9 |
import time
|
|
|
|
| 10 |
|
| 11 |
from gradio_motioncanvasplayer import MotionCanvasPlayer
|
| 12 |
|
| 13 |
# Just some example project that servers as a placholder in the beginning
|
| 14 |
example_project_path = "https://prathje-gradio-motioncanvasplayer.hf.space/gradio_api/file=/home/user/app/public/project-3.17.2.js"
|
| 15 |
|
| 16 |
-
def slow_echo(message, history):
|
| 17 |
-
for i in range(len(message)):
|
| 18 |
-
time.sleep(0.3)
|
| 19 |
-
yield "You typed: " + message[: i+1]
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def load_example(example):
|
| 27 |
return example['project_path'], example['code'], ""
|
|
@@ -32,8 +41,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as app:
|
|
| 32 |
with gr.Row():
|
| 33 |
with gr.Column():
|
| 34 |
gr.Markdown("## Chat")
|
| 35 |
-
chat = gr.ChatInterface(fn=
|
| 36 |
-
|
| 37 |
|
| 38 |
gr.Markdown("### TypeScript Code for Your Scene")
|
| 39 |
code = gr.Code(value="", language="typescript")
|
|
|
|
| 7 |
from threading import Timer
|
| 8 |
from functools import partial
|
| 9 |
import time
|
| 10 |
+
from huggingface_hub import InferenceClient
|
| 11 |
|
| 12 |
from gradio_motioncanvasplayer import MotionCanvasPlayer
|
| 13 |
|
| 14 |
# Just some example project that servers as a placholder in the beginning
|
| 15 |
example_project_path = "https://prathje-gradio-motioncanvasplayer.hf.space/gradio_api/file=/home/user/app/public/project-3.17.2.js"
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
client = InferenceClient(
|
| 19 |
+
provider="hf-inference",
|
| 20 |
+
api_key=os.environ["HF_TOKEN"],
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
def get_completion(prompt, history):
|
| 24 |
+
completion = client.chat.completions.create(
|
| 25 |
+
model="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 26 |
+
messages=[
|
| 27 |
+
{
|
| 28 |
+
"role": "user",
|
| 29 |
+
"content": "What is the capital of France?"
|
| 30 |
+
}
|
| 31 |
+
],
|
| 32 |
+
)
|
| 33 |
+
return completion.choices[0].message
|
| 34 |
|
| 35 |
def load_example(example):
|
| 36 |
return example['project_path'], example['code'], ""
|
|
|
|
| 41 |
with gr.Row():
|
| 42 |
with gr.Column():
|
| 43 |
gr.Markdown("## Chat")
|
| 44 |
+
chat = gr.ChatInterface(fn=get_completion, type="messages")
|
|
|
|
| 45 |
|
| 46 |
gr.Markdown("### TypeScript Code for Your Scene")
|
| 47 |
code = gr.Code(value="", language="typescript")
|