Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,14 @@ import gradio as gr
|
|
2 |
import os
|
3 |
from deep_translator import GoogleTranslator
|
4 |
from huggingface_hub import InferenceClient
|
5 |
-
from transformers import Conversation
|
6 |
|
7 |
# دریافت توکن از محیط (در Hugging Face Secrets تنظیم شود)
|
8 |
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
|
9 |
if not HF_TOKEN:
|
10 |
raise RuntimeError("Missing HUGGINGFACE_API_TOKEN secret")
|
11 |
|
12 |
-
# ساخت کلاینت
|
13 |
-
hf_client = InferenceClient(
|
14 |
-
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
15 |
-
token=HF_TOKEN
|
16 |
-
)
|
17 |
|
18 |
def generate_topics(field, major, keywords, audience, level):
|
19 |
# اعتبارسنجی ورودیها
|
@@ -31,18 +27,17 @@ def generate_topics(field, major, keywords, audience, level):
|
|
31 |
)
|
32 |
|
33 |
try:
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
temperature=0.7
|
|
|
42 |
)
|
43 |
-
|
44 |
-
# دریافت آخرین پاسخ مدل
|
45 |
-
english_output = conv.generated_responses[-1].strip()
|
46 |
|
47 |
# ترجمه به فارسی
|
48 |
try:
|
|
|
2 |
import os
|
3 |
from deep_translator import GoogleTranslator
|
4 |
from huggingface_hub import InferenceClient
|
|
|
5 |
|
6 |
# دریافت توکن از محیط (در Hugging Face Secrets تنظیم شود)
|
7 |
HF_TOKEN = os.environ.get("HUGGINGFACE_API_TOKEN")
|
8 |
if not HF_TOKEN:
|
9 |
raise RuntimeError("Missing HUGGINGFACE_API_TOKEN secret")
|
10 |
|
11 |
+
# ساخت کلاینت جدید
|
12 |
+
hf_client = InferenceClient(token=HF_TOKEN)
|
|
|
|
|
|
|
13 |
|
14 |
def generate_topics(field, major, keywords, audience, level):
|
15 |
# اعتبارسنجی ورودیها
|
|
|
27 |
)
|
28 |
|
29 |
try:
|
30 |
+
# فراخوانی مدل DeepSeek با استفاده از endpoint چت
|
31 |
+
response = hf_client.chat.completions.create(
|
32 |
+
model="deepseek-ai/DeepSeek-Prover-V2-671B",
|
33 |
+
messages=[
|
34 |
+
{"role": "system", "content": "You are an academic advisor assistant."},
|
35 |
+
{"role": "user", "content": prompt}
|
36 |
+
],
|
37 |
+
temperature=0.7,
|
38 |
+
max_tokens=512
|
39 |
)
|
40 |
+
english_output = response.choices[0].message.content.strip()
|
|
|
|
|
41 |
|
42 |
# ترجمه به فارسی
|
43 |
try:
|