Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
from transformers import pipeline
|
4 |
|
5 |
"""
|
6 |
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
|
7 |
"""
|
8 |
-
|
9 |
|
10 |
modelpath = "distilgpt2"
|
11 |
|
@@ -13,7 +13,7 @@ pipe = pipeline(
|
|
13 |
"text-generation",
|
14 |
model=modelpath
|
15 |
)
|
16 |
-
|
17 |
{"role": "system", "content": "You are a customer applying for a housing loan in India. Provide dummy details about your application and negotiate the terms."},
|
18 |
{"role": "user", "content": "Hi!Welcome to Hero Housing Finance!"},
|
19 |
{"role": "assistant", "content": "Hello, I would like to apply for a loan."},
|
@@ -33,30 +33,28 @@ def respond(
|
|
33 |
top_p,
|
34 |
):
|
35 |
messages = [{"role": "system", "content": system_message}]
|
36 |
-
try:
|
37 |
-
#add initil message to the conversation history
|
38 |
-
for msg in initial_messages:
|
39 |
-
messages.append(msg)
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
except Exception as e:
|
49 |
-
return f"Error: {str(e)}"
|
50 |
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
56 |
temperature=temperature,
|
57 |
top_p=top_p,
|
58 |
-
)
|
59 |
-
|
|
|
|
|
|
|
60 |
|
61 |
|
62 |
"""
|
@@ -80,4 +78,4 @@ demo = gr.ChatInterface(
|
|
80 |
|
81 |
|
82 |
if __name__ == "__main__":
|
83 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from huggingface_hub import InferenceClient
|
3 |
from transformers import pipeline
|
4 |
|
5 |
"""
|
6 |
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
|
7 |
"""
|
8 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
9 |
|
10 |
modelpath = "distilgpt2"
|
11 |
|
|
|
13 |
"text-generation",
|
14 |
model=modelpath
|
15 |
)
|
16 |
+
messages = [
|
17 |
{"role": "system", "content": "You are a customer applying for a housing loan in India. Provide dummy details about your application and negotiate the terms."},
|
18 |
{"role": "user", "content": "Hi!Welcome to Hero Housing Finance!"},
|
19 |
{"role": "assistant", "content": "Hello, I would like to apply for a loan."},
|
|
|
33 |
top_p,
|
34 |
):
|
35 |
messages = [{"role": "system", "content": system_message}]
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
for val in history:
|
38 |
+
if val[0]:
|
39 |
+
messages.append({"role": "user", "content": val[0]})
|
40 |
+
if val[1]:
|
41 |
+
messages.append({"role": "assistant", "content": val[1]})
|
42 |
|
43 |
+
messages.append({"role": "user", "content": message})
|
|
|
|
|
44 |
|
45 |
+
response = ""
|
46 |
|
47 |
+
for message in client.chat_completion(
|
48 |
+
messages,
|
49 |
+
max_tokens=max_tokens,
|
50 |
+
stream=True,
|
51 |
temperature=temperature,
|
52 |
top_p=top_p,
|
53 |
+
):
|
54 |
+
token = message.choices[0].delta.content
|
55 |
+
|
56 |
+
response += token
|
57 |
+
yield response
|
58 |
|
59 |
|
60 |
"""
|
|
|
78 |
|
79 |
|
80 |
if __name__ == "__main__":
|
81 |
+
demo.launch()
|