Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
+
load_dotenv()
|
| 6 |
+
HF_Token=os.getenv("HUGGINGFACEHUB_ACCESS_TOKEN")
|
| 7 |
+
|
| 8 |
+
Model_id="google/gemma-2-2b-it"
|
| 9 |
+
client=InferenceClient(model=Model_id, token=HF_Token)
|
| 10 |
+
message=[{"role": "system", "content": "Hello, my name is John. What is your name?"}]
|
| 11 |
+
|
| 12 |
+
print("type exit to quit.\n")
|
| 13 |
+
|
| 14 |
+
while True:
|
| 15 |
+
user_text=input("you: ").strip()
|
| 16 |
+
if(user_text.lower()=="exit"):
|
| 17 |
+
print("good bye")
|
| 18 |
+
break
|
| 19 |
+
message.append({"role": "user", "content": user_text})
|
| 20 |
+
try:
|
| 21 |
+
resp=client.chat_completion(messages=message,max_tokens=100,temperature=.7,stop=["\nUser","\nSystem: "])
|
| 22 |
+
bot_text=resp.choices[0].message["content"]
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print("bot Error:", e)
|
| 25 |
+
message.pop()
|
| 26 |
+
continue
|
| 27 |
+
print("bot:", bot_text+"\n")
|
| 28 |
+
message.append({"role": "assistant", "content": bot_text})
|