Spaces:
Runtime error
Runtime error
Update app/models.py
Browse files- app/models.py +39 -39
app/models.py
CHANGED
|
@@ -1,40 +1,40 @@
|
|
| 1 |
-
from transformers import pipeline
|
| 2 |
-
|
| 3 |
-
# وظيفة تلخيص النصوص
|
| 4 |
-
def summarize_text(document: str):
|
| 5 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
-
summary = summarizer(document, max_length=130, min_length=30, do_sample=False)
|
| 7 |
-
return summary[0]['summary_text']
|
| 8 |
-
|
| 9 |
-
# وظيفة تفسير الصور
|
| 10 |
-
def analyze_image(image):
|
| 11 |
-
image_analyzer = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
| 12 |
-
result = image_analyzer(image)
|
| 13 |
-
return result[0]['generated_text']
|
| 14 |
-
|
| 15 |
-
# وظيفة الإجابة على الأسئلة
|
| 16 |
-
def answer_question(question: str, document: str):
|
| 17 |
-
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 18 |
-
result = qa_pipeline(question=question, context=document)
|
| 19 |
-
return result['answer']
|
| 20 |
-
|
| 21 |
-
# وظيفة إنشاء تصورات بيانات
|
| 22 |
-
def generate_visualization(data, request):
|
| 23 |
-
import pandas as pd
|
| 24 |
-
import matplotlib.pyplot as plt
|
| 25 |
-
import seaborn as sns
|
| 26 |
-
|
| 27 |
-
df = pd.read_excel(data)
|
| 28 |
-
# تنفيذ الطلب (مثال: رسم مخطط)
|
| 29 |
-
if "bar" in request:
|
| 30 |
-
plt.bar(df['column_name'], df['values'])
|
| 31 |
-
elif "line" in request:
|
| 32 |
-
plt.plot(df['column_name'], df['values'])
|
| 33 |
-
plt.savefig("visualization.png")
|
| 34 |
-
return "visualization.png"
|
| 35 |
-
|
| 36 |
-
# وظيفة ترجمة المستندات
|
| 37 |
-
def translate_document(document, target_language):
|
| 38 |
-
translator = pipeline("translation", model=f"Helsinki-NLP/opus-mt-{target_language}")
|
| 39 |
-
translation = translator(document)
|
| 40 |
return translation[0]['translation_text']
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
|
| 3 |
+
# وظيفة تلخيص النصوص
|
| 4 |
+
def summarize_text(document: str):
|
| 5 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 6 |
+
summary = summarizer(document, max_length=130, min_length=30, do_sample=False)
|
| 7 |
+
return summary[0]['summary_text']
|
| 8 |
+
|
| 9 |
+
# وظيفة تفسير الصور
|
| 10 |
+
def analyze_image(image):
|
| 11 |
+
image_analyzer = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
|
| 12 |
+
result = image_analyzer(image)
|
| 13 |
+
return result[0]['generated_text']
|
| 14 |
+
|
| 15 |
+
# وظيفة الإجابة على الأسئلة
|
| 16 |
+
def answer_question(question: str, document: str):
|
| 17 |
+
qa_pipeline = pipeline("question-answering", model="deepset/roberta-base-squad2")
|
| 18 |
+
result = qa_pipeline(question=question, context=document)
|
| 19 |
+
return result['answer']
|
| 20 |
+
|
| 21 |
+
# وظيفة إنشاء تصورات بيانات
|
| 22 |
+
def generate_visualization(data, request):
|
| 23 |
+
import pandas as pd
|
| 24 |
+
import matplotlib.pyplot as plt
|
| 25 |
+
import seaborn as sns
|
| 26 |
+
|
| 27 |
+
df = pd.read_excel(data)
|
| 28 |
+
# تنفيذ الطلب (مثال: رسم مخطط)
|
| 29 |
+
if "bar" in request:
|
| 30 |
+
plt.bar(df['column_name'], df['values'])
|
| 31 |
+
elif "line" in request:
|
| 32 |
+
plt.plot(df['column_name'], df['values'])
|
| 33 |
+
plt.savefig("visualization.png")
|
| 34 |
+
return "visualization.png"
|
| 35 |
+
|
| 36 |
+
# وظيفة ترجمة المستندات
|
| 37 |
+
def translate_document(document, target_language):
|
| 38 |
+
translator = pipeline("translation", model=f"Helsinki-NLP/opus-mt-{target_language}")
|
| 39 |
+
translation = translator(document)
|
| 40 |
return translation[0]['translation_text']
|