Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,47 +1,38 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
# نمونه استفاده
|
40 |
-
prompt = "سلام، امروز چه خبر؟"
|
41 |
-
response_falcon = generate_response(prompt, model_name="falcon")
|
42 |
-
response_gpt_neox = generate_response(prompt, model_name="gpt_neox")
|
43 |
-
response_persian = generate_response(prompt, model_name="persian")
|
44 |
-
|
45 |
-
print("Falcon Response:", response_falcon)
|
46 |
-
print("GPT-NeoX Response:", response_gpt_neox)
|
47 |
-
print("Persian Response:", response_persian)
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
import jdatetime
|
4 |
+
from sympy import sympify
|
5 |
+
|
6 |
+
# مدل پرسش و پاسخ فارسی
|
7 |
+
qa_pipeline = pipeline("question-answering", model="Hooshvare/bert-fa-base-uncased", tokenizer="Hooshvare/bert-fa-base-uncased")
|
8 |
+
|
9 |
+
# توابع اصلی
|
10 |
+
def process_text(input_text):
|
11 |
+
# تحلیل سوال
|
12 |
+
if "تاریخ" in input_text:
|
13 |
+
today = jdatetime.date.today()
|
14 |
+
return f"امروز: {today}"
|
15 |
+
elif "محاسبه" in input_text:
|
16 |
+
expression = input_text.replace("محاسبه", "").strip()
|
17 |
+
try:
|
18 |
+
result = sympify(expression)
|
19 |
+
return f"نتیجه محاسبه: {result}"
|
20 |
+
except Exception as e:
|
21 |
+
return f"خطا در محاسبه: {e}"
|
22 |
+
else:
|
23 |
+
# پاسخ به سوال
|
24 |
+
context = "اینجا متنی برای مثال قرار دارد که هوش مصنوعی میتواند از آن پاسخ بدهد."
|
25 |
+
response = qa_pipeline({"question": input_text, "context": context})
|
26 |
+
return f"پاسخ: {response['answer']}"
|
27 |
+
|
28 |
+
# رابط کاربری Gradio
|
29 |
+
interface = gr.Interface(
|
30 |
+
fn=process_text,
|
31 |
+
inputs=gr.Textbox(lines=5, placeholder="سوال یا متن خود را وارد کنید..."),
|
32 |
+
outputs="text",
|
33 |
+
title="هوش مصنوعی فارسی",
|
34 |
+
description="پرسشهای خود را وارد کنید، محاسبات انجام دهید یا تاریخ امروز را دریافت کنید.",
|
35 |
+
)
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|