Spaces:
Running
Running
kenghuoxiong
commited on
Commit
•
cf2d6b2
1
Parent(s):
7b51a06
Update app.py
Browse files
app.py
CHANGED
@@ -16,19 +16,17 @@ from langchain_core.prompts import PromptTemplate
|
|
16 |
"""
|
17 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
18 |
"""
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
# temperature=0.8,)
|
23 |
|
24 |
-
# qa = RetrievalQA.from_chain_type(
|
25 |
-
# llm=client,
|
26 |
-
# chain_type="stuff",
|
27 |
-
# retriever=retriever,
|
28 |
-
# chain_type_kwargs=chain_type_kwargs,
|
29 |
-
# return_source_documents=True
|
30 |
-
# )
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
def respond(
|
34 |
message,
|
@@ -49,26 +47,29 @@ def respond(
|
|
49 |
messages.append({"role": "user", "content": message})
|
50 |
|
51 |
response = ""
|
52 |
-
|
53 |
-
for message in
|
54 |
-
|
55 |
max_tokens=max_tokens,
|
56 |
stream=True,
|
57 |
temperature=temperature,
|
58 |
top_p=top_p,
|
|
|
59 |
):
|
60 |
token = message.choices[0].delta.content
|
61 |
|
62 |
response += token
|
63 |
yield response
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
demo = gr.ChatInterface(
|
69 |
respond,
|
|
|
|
|
70 |
additional_inputs=[
|
71 |
-
gr.Textbox(
|
72 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
73 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
74 |
gr.Slider(
|
|
|
16 |
"""
|
17 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
18 |
"""
|
19 |
+
import gradio as gr
|
20 |
+
from openai import OpenAI
|
21 |
+
import os
|
|
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
TOKEN = os.getenv("HF_TOKEN")
|
25 |
+
|
26 |
+
client = OpenAI(
|
27 |
+
base_url="https://api-inference.huggingface.co/v1/",
|
28 |
+
api_key=TOKEN,
|
29 |
+
)
|
30 |
|
31 |
def respond(
|
32 |
message,
|
|
|
47 |
messages.append({"role": "user", "content": message})
|
48 |
|
49 |
response = ""
|
50 |
+
|
51 |
+
for message in client.chat.completions.create(
|
52 |
+
model="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
53 |
max_tokens=max_tokens,
|
54 |
stream=True,
|
55 |
temperature=temperature,
|
56 |
top_p=top_p,
|
57 |
+
messages=messages,
|
58 |
):
|
59 |
token = message.choices[0].delta.content
|
60 |
|
61 |
response += token
|
62 |
yield response
|
63 |
|
64 |
+
|
65 |
+
chatbot = gr.Chatbot(height=600)
|
66 |
+
|
67 |
demo = gr.ChatInterface(
|
68 |
respond,
|
69 |
+
fill_height=True,
|
70 |
+
chatbot=chatbot,
|
71 |
additional_inputs=[
|
72 |
+
gr.Textbox(label="System message"),
|
73 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
74 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
75 |
gr.Slider(
|