File size: 2,517 Bytes
5fdb69e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1) Import Required Libraries \n",
    "\n",
    "import requests\n",
    "import gradio as gr\n",
    "\n",
    "# Deepseek only uses abstract summarization\n",
    "# This tool use DeepSeek API Endpoint\n",
    "\n",
    "# 2) Define the DeepSeek API Endpoint\n",
    "\n",
    "OLLAMA_URL = \"http://localhost:11434/api/generate\"\n",
    "\n",
    "# 3) Define the Summarization Function which can retrieve Information\n",
    "\n",
    "def summarize_text(text):\n",
    "    payload = {\n",
    "        \"model\": \"deepseek-r1\", #Here you can load whatever the model you have in your ollama(ex:deepseek-r1:1.5b,7b,8b,14b) I used 7b model here \n",
    "        \"prompt\": f\"Summarize the following text in **5 bullet points**:\\n\\n{text}\", #The prompt is here for tell commands for the llm to act \n",
    "        \"stream\": False  # Ensures the response is returned as a whole, not streamed\n",
    "    }\n",
    "\n",
    "    response = requests.post(OLLAMA_URL, json=payload) #Send Requests to deepseekAPI\n",
    "\n",
    "    if response.status_code == 200: #if server run correctly it return the result or it will give error\n",
    "        return response.json().get(\"response\", \"No summary generated.\")\n",
    "    else:\n",
    "        return f\"Error: {response.text}\"\n",
    "\n",
    "# 4) Create Gradio interface to design \n",
    "interface = gr.Interface(\n",
    "    fn=summarize_text,\n",
    "    inputs=gr.Textbox(lines=10, placeholder=\"Enter text to summarize\"),\n",
    "    outputs=gr.Textbox(label=\"Summarized Text\"),\n",
    "    #theme='NoCrypt/miku', #Theme for the Interface I used Hatsune Miku from HF \n",
    "    title=\"AI-Powered Text Summarizer\",\n",
    "    description=\"Enter a long text and DeepSeek AI will generate a concise summary.\"\n",
    ")\n",
    "\n",
    "# Launch the web app\n",
    "if __name__ == \"__main__\":\n",
    "    interface.launch()\n",
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}