Spaces:
Sleeping
Sleeping
Nitzantry1
commited on
Commit
•
8c65a84
1
Parent(s):
b4da61e
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,19 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
-
from huggingface_hub import
|
4 |
|
5 |
model_id = 'dicta-il/dictalm-7b-instruct'
|
6 |
|
7 |
# יצירת API של Hugging Face
|
8 |
api_key = os.getenv('HUGGINGFACE_API_KEY', '')
|
9 |
-
generator =
|
10 |
|
11 |
# ×¤×•× ×§×¦×™×™×ª יצירת הטקסט
|
12 |
def chat_with_model(history):
|
13 |
prompt = history[-1]["content"]
|
14 |
try:
|
15 |
-
response = generator(prompt)
|
16 |
-
|
17 |
-
result = response["generated_text"]
|
18 |
-
else:
|
19 |
-
result = response
|
20 |
except Exception as e:
|
21 |
result = f"Error: {str(e)}"
|
22 |
return history + [{"role": "bot", "content": result}]
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
from huggingface_hub import InferenceClient
|
4 |
|
5 |
model_id = 'dicta-il/dictalm-7b-instruct'
|
6 |
|
7 |
# יצירת API של Hugging Face
|
8 |
api_key = os.getenv('HUGGINGFACE_API_KEY', '')
|
9 |
+
generator = InferenceClient(model=model_id, token=api_key)
|
10 |
|
11 |
# ×¤×•× ×§×¦×™×™×ª יצירת הטקסט
|
12 |
def chat_with_model(history):
|
13 |
prompt = history[-1]["content"]
|
14 |
try:
|
15 |
+
response = generator.text_generation(prompt, do_sample=True, min_length=20, max_length=64, top_k=40, top_p=0.92, temperature=0.9)
|
16 |
+
result = response.get("generated_text", "Error: No generated text found")
|
|
|
|
|
|
|
17 |
except Exception as e:
|
18 |
result = f"Error: {str(e)}"
|
19 |
return history + [{"role": "bot", "content": result}]
|