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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
import streamlit as st
|
3 |
import shutil
|
@@ -10,6 +538,15 @@ import urllib.request
|
|
10 |
import random
|
11 |
from gtts import gTTS
|
12 |
import sqlite3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
conn = sqlite3.connect('chatbot_data.db')
|
14 |
def main():
|
15 |
st.title("انیمه کردن تصاویر")
|
@@ -18,7 +555,9 @@ def main():
|
|
18 |
animate_image(image_link)
|
19 |
# ایجاد یک cursor
|
20 |
cursor = conn.cursor()
|
21 |
-
|
|
|
|
|
22 |
# ایجاد جدول برای ذخیره پاسخهای Chatbot
|
23 |
cursor.execute('''
|
24 |
CREATE TABLE IF NOT EXISTS chatbot_responses (
|
@@ -57,6 +596,18 @@ def chatgpt4(text):
|
|
57 |
s = requests.Session()
|
58 |
r = random.randint(0, 1)
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
if r == 0:
|
61 |
chat = s.get(f"http://api-free.ir/api/bard.php?text={text}").json()["result"]
|
62 |
return chat
|
@@ -64,6 +615,13 @@ def chatgpt4(text):
|
|
64 |
else:
|
65 |
chat_2 = s.get(f"http://api-free.ir/api/chat.php?text={text}").json()["result"]
|
66 |
return chat_2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
def download_logo_and_save(text):
|
68 |
random_logo_url = fetch_random_logo(text)
|
69 |
if random_logo_url:
|
@@ -141,6 +699,15 @@ def download_and_save_music(file_path, music_link):
|
|
141 |
|
142 |
# https://chatgpt.ai/
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
def get_random_music_link():
|
145 |
api_url = "https://api-free.ir/api/music/"
|
146 |
response = requests.get(api_url)
|
@@ -177,7 +744,7 @@ if inp:
|
|
177 |
with open("downloaded_image.jpg", "wb") as out_file:
|
178 |
|
179 |
shutil.copyfileobj(response.raw, out_file)
|
180 |
-
st.image("downloaded_image.jpg"
|
181 |
|
182 |
|
183 |
|
@@ -307,7 +874,7 @@ if inp:
|
|
307 |
# ذخیره تصویر با نام خاص
|
308 |
image_name = "random_image.jpg"
|
309 |
image.save(image_name)
|
310 |
-
st.image("random_image.jpg"
|
311 |
|
312 |
|
313 |
elif inp.startswith("عکس"):
|
@@ -472,7 +1039,82 @@ if inp:
|
|
472 |
st.image(image, caption='تصویر استخاره', use_column_width=True)
|
473 |
else:
|
474 |
st.error("خطا در دریافت اطلاعات استخاره")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
475 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
476 |
|
477 |
|
478 |
|
@@ -513,13 +1155,15 @@ if inp:
|
|
513 |
st.text_area("Chatbot's Response", value=chat , height=400)
|
514 |
insert_chatbot_response(inp, chat)
|
515 |
|
|
|
|
|
|
|
|
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
-
|
522 |
-
|
523 |
|
524 |
|
525 |
except Exception as e:
|
|
|
1 |
+
# import requests
|
2 |
+
# import streamlit as st
|
3 |
+
# import shutil
|
4 |
+
# import random
|
5 |
+
# import gtts
|
6 |
+
# import requests
|
7 |
+
# from PIL import Image, ImageDraw, ImageFont
|
8 |
+
# from io import BytesIO
|
9 |
+
# import urllib.request
|
10 |
+
# import random
|
11 |
+
# from gtts import gTTS
|
12 |
+
# import sqlite3
|
13 |
+
# conn = sqlite3.connect('chatbot_data.db')
|
14 |
+
# def main():
|
15 |
+
# st.title("انیمه کردن تصاویر")
|
16 |
+
# image_link = st.text_input("لطفاً لینک عکس را وارد کنید:")
|
17 |
+
# if st.button("انیمه کردن"):
|
18 |
+
# animate_image(image_link)
|
19 |
+
# # ایجاد یک cursor
|
20 |
+
# cursor = conn.cursor()
|
21 |
+
|
22 |
+
# # ایجاد جدول برای ذخیره پاسخهای Chatbot
|
23 |
+
# cursor.execute('''
|
24 |
+
# CREATE TABLE IF NOT EXISTS chatbot_responses (
|
25 |
+
# id INTEGER PRIMARY KEY AUTOINCREMENT,
|
26 |
+
# user_input TEXT,
|
27 |
+
# bot_response TEXT
|
28 |
+
# )
|
29 |
+
|
30 |
+
# ''')
|
31 |
+
# def fetch_estekhare():
|
32 |
+
# url = "http://api-free.ir/api/es.php"
|
33 |
+
# response = requests.get(url)
|
34 |
+
# data = response.json()
|
35 |
+
# return data
|
36 |
+
# def animate_image(image_link):
|
37 |
+
# # لینک وبسرویس
|
38 |
+
# url = f'http://api-free.ir/api/enime/?img={image_link}'
|
39 |
+
|
40 |
+
# # دریافت نتیجه وبسرویس
|
41 |
+
# response = requests.get(url)
|
42 |
+
# data = response.json()
|
43 |
+
|
44 |
+
# # چک کردن صحت دریافت نتیجه
|
45 |
+
# if data['ok']:
|
46 |
+
# # دریافت لینک عکس انیمه شده
|
47 |
+
# image_url = data['result']
|
48 |
+
|
49 |
+
# # دریافت عکس و نمایش آن
|
50 |
+
# image_response = requests.get(image_url)
|
51 |
+
# image_data = Image.open(BytesIO(image_response.content))
|
52 |
+
# st.image(image_data, caption='تصویر انیمه شده')
|
53 |
+
# st.success("تصویر انیمه شده با موفقیت ذخیره شد.")
|
54 |
+
# else:
|
55 |
+
# st.error("دریافت نتیجه انیمه شده با مشکل مواجه شده است.")
|
56 |
+
# def chatgpt4(text):
|
57 |
+
# s = requests.Session()
|
58 |
+
# r = random.randint(0, 1)
|
59 |
+
|
60 |
+
# if r == 0:
|
61 |
+
# chat = s.get(f"http://api-free.ir/api/bard.php?text={text}").json()["result"]
|
62 |
+
# return chat
|
63 |
+
|
64 |
+
# else:
|
65 |
+
# chat_2 = s.get(f"http://api-free.ir/api/chat.php?text={text}").json()["result"]
|
66 |
+
# return chat_2
|
67 |
+
# def download_logo_and_save(text):
|
68 |
+
# random_logo_url = fetch_random_logo(text)
|
69 |
+
# if random_logo_url:
|
70 |
+
# try:
|
71 |
+
# response = requests.get(random_logo_url)
|
72 |
+
# image = Image.open(BytesIO(response.content))
|
73 |
+
# st.image(image, caption='Generated Logo', use_column_width=True)
|
74 |
+
# st.success("Logo saved successfully.")
|
75 |
+
# except Exception as e:
|
76 |
+
# st.error("Error occurred while saving logo:", e)
|
77 |
+
# else:
|
78 |
+
# st.warning("No logos found.")
|
79 |
+
# # def fetch_random_logo(text):
|
80 |
+
# # url = f"https://api-free.ir/api/Logo-top.php?text={text}&page={str(random.randint(1, 99))}"
|
81 |
+
|
82 |
+
# # try:
|
83 |
+
# # response = requests.get(url)
|
84 |
+
# # data = response.json()
|
85 |
+
# # if 'result' in data and data['result']:
|
86 |
+
# # return random.choice(data['result'])
|
87 |
+
# # else:
|
88 |
+
# # st.error("Error: No logos found.")
|
89 |
+
# # return None
|
90 |
+
# # except Exception as e:
|
91 |
+
# # st.error("Error occurred:", e)
|
92 |
+
# # return None
|
93 |
+
|
94 |
+
# def download_logo(logo_url):
|
95 |
+
# try:
|
96 |
+
# response = requests.get(logo_url)
|
97 |
+
# image = Image.open(BytesIO(response.content))
|
98 |
+
# st.image(image, caption='Generated Logo', use_column_width=True)
|
99 |
+
# st.success("Logo saved successfully.")
|
100 |
+
# except Exception as e:
|
101 |
+
# st.error("Error occurred while saving logo:", e)
|
102 |
+
|
103 |
+
# # اضافه کردن پاسخ Chatbot به جدول
|
104 |
+
# def insert_chatbot_response(user_input, bot_response):
|
105 |
+
# cursor.execute('INSERT INTO chatbot_responses (user_input, bot_response) VALUES (?, ?)', (user_input, bot_response))
|
106 |
+
# conn.commit()
|
107 |
+
# # تنظیمات صفحه را سفارشی کنید
|
108 |
+
# st.set_page_config(
|
109 |
+
# page_title="ChatGPT",
|
110 |
+
# page_icon="🤖",
|
111 |
+
# layout="wide",
|
112 |
+
# initial_sidebar_state="expanded",
|
113 |
+
|
114 |
+
|
115 |
+
# )
|
116 |
+
|
117 |
+
# def fetch_random_logo(text):
|
118 |
+
# page = random.randint(1, 99)
|
119 |
+
# url = f"https://api-free.ir/api/Logo-top.php?text={text}&page={page}"
|
120 |
+
|
121 |
+
# try:
|
122 |
+
# response = requests.get(url)
|
123 |
+
# data = response.json()
|
124 |
+
# if 'result' in data and data['result']:
|
125 |
+
# # انتخاب یک لینک تصادفی از لیست لینکهای لوگوها
|
126 |
+
# random_logo_url = random.choice(data['result'])
|
127 |
+
# return random_logo_url
|
128 |
+
# else:
|
129 |
+
# st.error("Error: No logos found.")
|
130 |
+
# return None
|
131 |
+
# except Exception as e:
|
132 |
+
# st.error("Error occurred:", e)
|
133 |
+
# return None
|
134 |
+
|
135 |
+
|
136 |
+
# def download_and_save_music(file_path, music_link):
|
137 |
+
# response = requests.get(music_link)
|
138 |
+
# if response.status_code == 200:
|
139 |
+
# with open(file_path, "wb") as file:
|
140 |
+
# file.write(response.content)
|
141 |
+
|
142 |
+
# # https://chatgpt.ai/
|
143 |
+
|
144 |
+
# def get_random_music_link():
|
145 |
+
# api_url = "https://api-free.ir/api/music/"
|
146 |
+
# response = requests.get(api_url)
|
147 |
+
# if response.status_code == 200:
|
148 |
+
# data = response.json()
|
149 |
+
# if data.get("ok") and data.get("result") and data["result"].get("song"):
|
150 |
+
# return data["result"]["song"]
|
151 |
+
# return None
|
152 |
+
|
153 |
+
# st.image('ai.jpg', width=100)
|
154 |
+
# st.title('ChatGPT')
|
155 |
+
# st.subheader('Free-GPT-Chat')
|
156 |
+
|
157 |
+
# inp = st.chat_input('درخواست خود را وارد کنید')
|
158 |
+
|
159 |
+
# if inp:
|
160 |
+
# if inp.startswith("تصویر"):
|
161 |
+
# st.text('در حال بارگیری...')
|
162 |
+
# image = inp.replace("تصویر","").strip()
|
163 |
+
# try :
|
164 |
+
|
165 |
+
# response = requests.get(f"http://api-free.ir/api/img.php?text={image}&v=3.5")
|
166 |
+
# response.raise_for_status()
|
167 |
+
|
168 |
+
# data = response.json()
|
169 |
+
# result = data["result"]
|
170 |
+
|
171 |
+
# # انتخاب یک عنصر تصادفی از لیست result
|
172 |
+
# random_link = random.choice(result)
|
173 |
+
|
174 |
+
# response = requests.get(random_link, stream=True)
|
175 |
+
# response.raise_for_status()
|
176 |
+
|
177 |
+
# with open("downloaded_image.jpg", "wb") as out_file:
|
178 |
+
|
179 |
+
# shutil.copyfileobj(response.raw, out_file)
|
180 |
+
# st.image("downloaded_image.jpg", use_column_width=True)
|
181 |
+
|
182 |
+
|
183 |
+
|
184 |
+
|
185 |
+
# except requests.exceptions.RequestException as e:
|
186 |
+
# st.error(f"خطا در دریافت تصویر: {e}")
|
187 |
+
# elif inp.startswith("مونث"):
|
188 |
+
|
189 |
+
# text = inp.replace("مونث", "").strip()
|
190 |
+
# st.text('در حال پردازش ویس')
|
191 |
+
|
192 |
+
|
193 |
+
|
194 |
+
# # تبدیل متن به صدا
|
195 |
+
# try:
|
196 |
+
# response = requests.get(f"https://api-free.ir/api/voice.php?text={text}&mod=DilaraNeural")
|
197 |
+
# response.raise_for_status() # بررسی موفقیت درخواست
|
198 |
+
|
199 |
+
# result_url = response.json()["result"]
|
200 |
+
# voice_response = requests.get(result_url)
|
201 |
+
|
202 |
+
# voice_response.raise_for_status()
|
203 |
+
|
204 |
+
|
205 |
+
# with open('voice_bot.mp3', "wb") as f:
|
206 |
+
|
207 |
+
# f.write(voice_response.content)
|
208 |
+
# st.audio("voice_bot.mp3", format='audio/mp3')
|
209 |
+
# except requests.exceptions.RequestException as mz:
|
210 |
+
|
211 |
+
|
212 |
+
# st.error(f"erorr:\n{mz}")
|
213 |
+
|
214 |
+
|
215 |
+
# #
|
216 |
+
|
217 |
+
# elif inp.startswith("مذکر"):
|
218 |
+
# text_man = inp.replace("مذکر", "").strip()
|
219 |
+
# st.text('در حال پردازش ویس')
|
220 |
+
# response = requests.get(f"https://api-free.ir/api/voice.php?text={text_man}&mod=FaridNeural")
|
221 |
+
# response.raise_for_status() # بررسی موفقیت درخواست
|
222 |
+
|
223 |
+
# result_url = response.json()["result"]
|
224 |
+
# voice_response = requests.get(result_url)
|
225 |
+
# try:
|
226 |
+
|
227 |
+
|
228 |
+
# voice_response.raise_for_status()
|
229 |
+
# with open('voice_bot_man.mp3', "wb") as f:
|
230 |
+
|
231 |
+
|
232 |
+
# f.write(voice_response.content)
|
233 |
+
# st.audio("voice_bot_man.mp3", format='audio/mp3')
|
234 |
+
# except requests.exceptions.RequestException as m:
|
235 |
+
# st.error(f"erorr:\n{m}")
|
236 |
+
# elif inp.startswith("voice"):
|
237 |
+
|
238 |
+
|
239 |
+
# text = inp.replace("voice", "").strip()
|
240 |
+
|
241 |
+
# st.text('در حال پردازش ویس')
|
242 |
+
|
243 |
+
# tts = gTTS(text)
|
244 |
+
# tts.save("responsee.mp3")
|
245 |
+
# st.audio("responsee.mp3", format='audio/mp3')
|
246 |
+
|
247 |
+
|
248 |
+
|
249 |
+
# # پخش صدا
|
250 |
+
# # os.system("start response.mp3")
|
251 |
+
|
252 |
+
# elif inp =="اهنگ"or inp =="music":
|
253 |
+
# st.text("منتظربمانید که اهگ اماده بشه")
|
254 |
+
# random_music_link = get_random_music_link()
|
255 |
+
# try:
|
256 |
+
# if random_music_link:
|
257 |
+
# music_file_name = "random_music.mp3"
|
258 |
+
# download_and_save_music(music_file_name, random_music_link)
|
259 |
+
# with open(music_file_name, 'rb') as music_file:
|
260 |
+
# st.audio('random_music.mp3',format='audio/mp3')
|
261 |
+
# except Exception as m:
|
262 |
+
# st.error(f"erorr:\n {m}")
|
263 |
+
# elif inp=="bg" or inp =="بگراند":
|
264 |
+
# st.text("منتظربمانید که بگراند ارسال شه")
|
265 |
+
# # لیست مدلها
|
266 |
+
# model_list = [
|
267 |
+
# "animals",
|
268 |
+
# "stock-images",
|
269 |
+
# "travel",
|
270 |
+
# "nature",
|
271 |
+
# "military",
|
272 |
+
# "hi-tech",
|
273 |
+
# "games",
|
274 |
+
# "celebrities",
|
275 |
+
# "art",
|
276 |
+
# "architecture",
|
277 |
+
# "abstract",
|
278 |
+
|
279 |
+
# ]
|
280 |
+
|
281 |
+
# # URL وبسرویس
|
282 |
+
# url_template = "https://api-free.ir/api/background2.php?page=1&text={}"
|
283 |
+
|
284 |
+
# # تولید لینک برای یک مدل تصادفی
|
285 |
+
# random_model = random.choice(model_list)
|
286 |
+
# url = url_template.format(random_model)
|
287 |
+
|
288 |
+
# # ارسال درخواست و دریافت پاسخ
|
289 |
+
# response = requests.get(url)
|
290 |
+
|
291 |
+
# # تبدیل پاسخ به دیکشنری
|
292 |
+
# data = response.json()
|
293 |
+
|
294 |
+
# # استخراج لینکهای عکس از پاسخ
|
295 |
+
# image_links = data.get('result', [])
|
296 |
+
|
297 |
+
# # انتخاب تصویر تصادفی
|
298 |
+
# random_image_link = random.choice(image_links)
|
299 |
+
|
300 |
+
# # دانلود تصویر
|
301 |
+
# image_response = requests.get(random_image_link)
|
302 |
+
# image = Image.open(BytesIO(image_response.content))
|
303 |
+
|
304 |
+
# # نمایش تصویر
|
305 |
+
|
306 |
+
|
307 |
+
# # ذخیره تصویر با نام خاص
|
308 |
+
# image_name = "random_image.jpg"
|
309 |
+
# image.save(image_name)
|
310 |
+
# st.image("random_image.jpg",use_column_width=True)
|
311 |
+
|
312 |
+
|
313 |
+
# elif inp.startswith("عکس"):
|
314 |
+
|
315 |
+
# st.text('در حال بارگیری...')
|
316 |
+
|
317 |
+
# image = inp.replace("عکس","").strip()
|
318 |
+
# try :
|
319 |
+
|
320 |
+
# response = requests.get(f"http://api-free.ir/api/img.php?text={image}&v=3.5")
|
321 |
+
# response.raise_for_status()
|
322 |
+
|
323 |
+
# data = response.json()
|
324 |
+
# result = data["result"]
|
325 |
+
|
326 |
+
# # انتخاب یک عنصر تصادفی از لیست result
|
327 |
+
# random_link = random.choice(result)
|
328 |
+
|
329 |
+
# response = requests.get(random_link, stream=True)
|
330 |
+
# response.raise_for_status()
|
331 |
+
|
332 |
+
# with open("downloaded_image.jpg", "wb") as out_file:
|
333 |
+
|
334 |
+
# shutil.copyfileobj(response.raw, out_file)
|
335 |
+
# st.image("downloaded_image.jpg", use_column_width=True)
|
336 |
+
|
337 |
+
|
338 |
+
|
339 |
+
|
340 |
+
# except requests.exceptions.RequestException as e:
|
341 |
+
# st.error(f"خطا در دریافت تصویر: {e}")
|
342 |
+
# elif inp.startswith("موزیک"):
|
343 |
+
# st.text("منتظرسرچ موزیک وارسال آن باشید")
|
344 |
+
# query = inp.replace("موزیک","")
|
345 |
+
# url = f"https://api-free.ir/api/sr-music/?text={query}"
|
346 |
+
# response = requests.get(url)
|
347 |
+
|
348 |
+
|
349 |
+
# if response.status_code == 200:
|
350 |
+
# data = response.json()
|
351 |
+
|
352 |
+
|
353 |
+
# # دریافت لینک فایل صوتی از دیکشنری result
|
354 |
+
# song_url = data["result"]["song"]
|
355 |
+
|
356 |
+
|
357 |
+
# # دانلود فایل صوتی
|
358 |
+
# urllib.request.urlretrieve(song_url, "music_plyar.mp3")
|
359 |
+
|
360 |
+
# with open("music_plyar.mp3","rb") as m:
|
361 |
+
# st.audio('music_plyar.mp3',format='audio/mp3')
|
362 |
+
|
363 |
+
# m.close()
|
364 |
+
# elif inp.startswith("font"):
|
365 |
+
# st.text("درحال ساخت فونت ")
|
366 |
+
# a =inp.replace("font","")
|
367 |
+
# fonts = requests.get(f'http://api-free.ir/api/font.php?en={a}').json()["result"]
|
368 |
+
# formatted_fonts = "\n".join([f"{index + 1}. {font}" for index, font in enumerate(fonts)])
|
369 |
+
# try:
|
370 |
+
|
371 |
+
# st.text_area("Chatbot's Response", value=f"فونتهای شما:\n{formatted_fonts}" , height=400)
|
372 |
+
# # font_to_database(fonts)
|
373 |
+
|
374 |
+
|
375 |
+
# except Exception as f:
|
376 |
+
|
377 |
+
# st.text_area("Chatbot's Response", value=f"erorr:\n{f}" , height=400)
|
378 |
+
# elif inp.startswith("فونت"):
|
379 |
+
# st.text("درحال ساخت فونت ")
|
380 |
+
# a =inp.replace("font","")
|
381 |
+
# fonts = requests.get(f'http://api-free.ir/api/font.php?fa={a}').json()["result"]
|
382 |
+
# formatted_fonts = "\n".join([f"{index + 1}. {font}" for index, font in enumerate(fonts)])
|
383 |
+
# try:
|
384 |
+
|
385 |
+
# st.text_area("Chatbot's Response", value=f"فونتهای شما:\n{formatted_fonts}" , height=400)
|
386 |
+
# # font_to_database(fonts)
|
387 |
+
|
388 |
+
|
389 |
+
# except Exception as f:
|
390 |
+
# st.error(f"erorr:\n{f}")
|
391 |
+
|
392 |
+
|
393 |
+
# # st.text_area("Chatbot's Response", value=f"erorr:\n{f}" , height=400)
|
394 |
+
|
395 |
+
# elif inp == "چنل" or inp == "کانال":
|
396 |
+
|
397 |
+
# st.markdown("[Python Channel](https://t.me/pythonsource1384)")
|
398 |
+
|
399 |
+
|
400 |
+
|
401 |
+
|
402 |
+
# elif inp.startswith("logo"):
|
403 |
+
# text = inp.replace("logo","").strip()
|
404 |
+
# a=download_logo_and_save(text)
|
405 |
+
# elif inp.startswith("anime"):
|
406 |
+
|
407 |
+
# st.text('در حال انیمه کردن')
|
408 |
+
# image_link = inp.replace("anime", "").strip()
|
409 |
+
|
410 |
+
# try:
|
411 |
+
# response = requests.get(f"http://api-free.ir/api/enime/?img={image_link}")
|
412 |
+
# response.raise_for_status()
|
413 |
+
# data = response.json()
|
414 |
+
|
415 |
+
# if data.get('ok'):
|
416 |
+
# image_url = data['result']
|
417 |
+
# image_response = requests.get(image_url)
|
418 |
+
# image_data = Image.open(BytesIO(image_response.content))
|
419 |
+
# st.image(image_data, caption='تصویر انیمه شده', use_column_width=False)
|
420 |
+
# st.success("تصویر انیمه شده با موفقیت ذخیره شد.")
|
421 |
+
# else:
|
422 |
+
# st.error("خطا در انیمه کردن تصویر.")
|
423 |
+
# except requests.exceptions.RequestException as e:
|
424 |
+
# st.error(f"خطا در دریافت تصویر: {e}")
|
425 |
+
# elif inp.startswith("انیمه"):
|
426 |
+
|
427 |
+
|
428 |
+
# st.text('در حال انیمه کردن')
|
429 |
+
# image_link = inp.replace("انیمه", "").strip()
|
430 |
+
|
431 |
+
# try:
|
432 |
+
# response = requests.get(f"http://api-free.ir/api/enime/?img={image_link}")
|
433 |
+
# response.raise_for_status()
|
434 |
+
# data = response.json()
|
435 |
+
|
436 |
+
# if data.get('ok'):
|
437 |
+
# image_url = data['result']
|
438 |
+
# image_response = requests.get(image_url)
|
439 |
+
# image_data = Image.open(BytesIO(image_response.content))
|
440 |
+
# st.image(image_data, caption='تصویر انیمه شده', use_column_width=False)
|
441 |
+
# st.success("تصویر انیمه شده با موفقیت ذخیره شد.")
|
442 |
+
# else:
|
443 |
+
# st.error("خطا در انیمه کردن تصویر.")
|
444 |
+
# except requests.exceptions.RequestException as e:
|
445 |
+
# st.error(f"خطا در دریافت تصویر: {e}")
|
446 |
+
|
447 |
+
|
448 |
+
|
449 |
+
# elif inp =="استخاره":
|
450 |
+
|
451 |
+
|
452 |
+
|
453 |
+
# estekhare_data = fetch_estekhare()
|
454 |
+
|
455 |
+
|
456 |
+
|
457 |
+
# if estekhare_data["ok"]:
|
458 |
+
# # Display result
|
459 |
+
# st.subheader("نتیجه استخاره:")
|
460 |
+
# st.write(f"سوره: {estekhare_data['result']['soreh']}")
|
461 |
+
# st.write(f"آیه: {estekhare_data['result']['ayeh']}")
|
462 |
+
# st.write(f"نتیجه: {estekhare_data['result']['natijeh']}")
|
463 |
+
# st.write(f"نتیجه کلی: {estekhare_data['result']['natijeh_kolli']}")
|
464 |
+
# st.write(f"نتیجه ازدواج: {estekhare_data['result']['natijeh_ezdevaj']}")
|
465 |
+
# st.write(f"نتیجه معامله: {estekhare_data['result']['natijeh_moameleh']}")
|
466 |
+
|
467 |
+
# # Display image
|
468 |
+
# st.subheader("تصویر مرتبط:")
|
469 |
+
# image_url = estekhare_data["result"]["image"]
|
470 |
+
# image_response = requests.get(image_url)
|
471 |
+
# image = Image.open(BytesIO(image_response.content))
|
472 |
+
# st.image(image, caption='تصویر استخاره', use_column_width=True)
|
473 |
+
# else:
|
474 |
+
# st.error("خطا در دریافت اطلاعات استخاره")
|
475 |
+
|
476 |
+
|
477 |
+
|
478 |
+
|
479 |
+
|
480 |
+
|
481 |
+
|
482 |
+
|
483 |
+
|
484 |
+
|
485 |
+
|
486 |
+
|
487 |
+
|
488 |
+
|
489 |
+
|
490 |
+
|
491 |
+
|
492 |
+
|
493 |
+
|
494 |
+
|
495 |
+
|
496 |
+
|
497 |
+
|
498 |
+
|
499 |
+
|
500 |
+
|
501 |
+
|
502 |
+
|
503 |
+
|
504 |
+
|
505 |
+
# else:
|
506 |
+
# st.text(' منتظربمانید برای پاسخ')
|
507 |
+
# try:
|
508 |
+
|
509 |
+
# chat =chatgpt4(inp)
|
510 |
+
|
511 |
+
|
512 |
+
|
513 |
+
# st.text_area("Chatbot's Response", value=chat , height=400)
|
514 |
+
# insert_chatbot_response(inp, chat)
|
515 |
+
|
516 |
+
|
517 |
+
|
518 |
+
|
519 |
+
|
520 |
+
|
521 |
+
|
522 |
+
|
523 |
+
|
524 |
+
|
525 |
+
# except Exception as e:
|
526 |
+
# st.text_area("Error", value=f"An error occurred: {e}", height=200)
|
527 |
+
|
528 |
+
|
529 |
import requests
|
530 |
import streamlit as st
|
531 |
import shutil
|
|
|
538 |
import random
|
539 |
from gtts import gTTS
|
540 |
import sqlite3
|
541 |
+
import logging
|
542 |
+
import time
|
543 |
+
from time import strftime
|
544 |
+
import datetime
|
545 |
+
import khayyam
|
546 |
+
from IPython.display import HTML
|
547 |
+
from bs4 import BeautifulSoup
|
548 |
+
import base64
|
549 |
+
import os
|
550 |
conn = sqlite3.connect('chatbot_data.db')
|
551 |
def main():
|
552 |
st.title("انیمه کردن تصاویر")
|
|
|
555 |
animate_image(image_link)
|
556 |
# ایجاد یک cursor
|
557 |
cursor = conn.cursor()
|
558 |
+
LOG_FILE = 'user_logs.log'
|
559 |
+
LOG_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
|
560 |
+
logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format=LOG_FORMAT)
|
561 |
# ایجاد جدول برای ذخیره پاسخهای Chatbot
|
562 |
cursor.execute('''
|
563 |
CREATE TABLE IF NOT EXISTS chatbot_responses (
|
|
|
596 |
s = requests.Session()
|
597 |
r = random.randint(0, 1)
|
598 |
|
599 |
+
if r == 0:
|
600 |
+
chat = s.get(f"http://api-free.ir/api/bard.php?text={text}").json()["result"]
|
601 |
+
return chat
|
602 |
+
|
603 |
+
else:
|
604 |
+
chat_2 = s.get(f"http://api-free.ir/api/chat.php?text={text}").json()["result"]
|
605 |
+
return chat_2
|
606 |
+
|
607 |
+
def chatgpt4(text):
|
608 |
+
s = requests.Session()
|
609 |
+
r = random.randint(0, 1)
|
610 |
+
|
611 |
if r == 0:
|
612 |
chat = s.get(f"http://api-free.ir/api/bard.php?text={text}").json()["result"]
|
613 |
return chat
|
|
|
615 |
else:
|
616 |
chat_2 = s.get(f"http://api-free.ir/api/chat.php?text={text}").json()["result"]
|
617 |
return chat_2
|
618 |
+
|
619 |
+
# اضافه شده
|
620 |
+
def add_something(text):
|
621 |
+
s = requests.Session()
|
622 |
+
added_text = s.get(f"http://api-free.ir/api/bard.php?text={text}").json()["text"]
|
623 |
+
return added_text
|
624 |
+
|
625 |
def download_logo_and_save(text):
|
626 |
random_logo_url = fetch_random_logo(text)
|
627 |
if random_logo_url:
|
|
|
699 |
|
700 |
# https://chatgpt.ai/
|
701 |
|
702 |
+
def save_to_file(filename, content):
|
703 |
+
with open(filename, 'w', encoding='utf-8') as file:
|
704 |
+
file.write(content)
|
705 |
+
|
706 |
+
def download_image(img_data, folder):
|
707 |
+
img_data = img_data.split(',')[1] # جدا کردن بخش اطلاعاتی از دادههای تصویر
|
708 |
+
img_binary = base64.b64decode(img_data) # رمزگشایی دادههای باینری تصویر
|
709 |
+
with open(os.path.join(folder, f'image_{len(os.listdir(folder)) + 1}.png'), 'wb') as file:
|
710 |
+
file.write(img_binary)
|
711 |
def get_random_music_link():
|
712 |
api_url = "https://api-free.ir/api/music/"
|
713 |
response = requests.get(api_url)
|
|
|
744 |
with open("downloaded_image.jpg", "wb") as out_file:
|
745 |
|
746 |
shutil.copyfileobj(response.raw, out_file)
|
747 |
+
st.image("downloaded_image.jpg")
|
748 |
|
749 |
|
750 |
|
|
|
874 |
# ذخیره تصویر با نام خاص
|
875 |
image_name = "random_image.jpg"
|
876 |
image.save(image_name)
|
877 |
+
st.image("random_image.jpg")
|
878 |
|
879 |
|
880 |
elif inp.startswith("عکس"):
|
|
|
1039 |
st.image(image, caption='تصویر استخاره', use_column_width=True)
|
1040 |
else:
|
1041 |
st.error("خطا در دریافت اطلاعات استخاره")
|
1042 |
+
elif inp =="time" or inp =="تایم":
|
1043 |
+
current_time = time.strftime("%H:%M:%S")
|
1044 |
+
now = datetime.now()
|
1045 |
+
a=now.strftime("%H:%M:%S")
|
1046 |
+
m=now.strftime("%Y-%m-%d")
|
1047 |
+
st.text_area("Chatbot's Response", value=f"تایم کنونی :{m}" , height=400)
|
1048 |
+
elif inp =="تاریخ":
|
1049 |
+
tariq =khayyam.JalaliDatetime.today().strftime("%A %D %B %Y")
|
1050 |
+
st.text_area("Chatbot's Response", value=f"تاریخ شما:\n{tariq}" , height=400)
|
1051 |
|
1052 |
+
elif inp.startswith("سورس"):
|
1053 |
+
url=inp.replace("سورس","")
|
1054 |
+
response = requests.get(url)
|
1055 |
+
if response.status_code == 200:
|
1056 |
+
st.text("در حال دانلود قالب سایت")
|
1057 |
+
|
1058 |
+
|
1059 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
1060 |
+
|
1061 |
+
# استخراج و ذخیره قالب وبسایت
|
1062 |
+
website_template = soup.prettify()
|
1063 |
+
save_to_file('website_template.html', website_template)
|
1064 |
+
|
1065 |
+
# استخراج و ذخیره کدهای CSS
|
1066 |
+
css_code = '\n'.join([style.get_text() for style in soup.find_all('style')])
|
1067 |
+
save_to_file('css_code.css', css_code)
|
1068 |
+
|
1069 |
+
# استخراج و ذخیره کدهای JavaScript
|
1070 |
+
js_code = '\n'.join([script.get_text() for script in soup.find_all('script') if script.get('src') is None])
|
1071 |
+
save_to_file('js_code.js', js_code)
|
1072 |
+
|
1073 |
+
# ساخت پوشه برای ذخیره تصاویر
|
1074 |
+
image_folder = 'images'
|
1075 |
+
os.makedirs(image_folder, exist_ok=True)
|
1076 |
+
|
1077 |
+
# دانلود و ذخیره تصاویر
|
1078 |
+
for img in soup.find_all('img'):
|
1079 |
+
img_data = img.get('src')
|
1080 |
+
if img_data and img_data.startswith('data:image'):
|
1081 |
+
download_image(img_data, image_folder)
|
1082 |
+
|
1083 |
+
st.write("Website template, CSS code, JavaScript code, and images saved successfully!")
|
1084 |
+
st.write("Displaying the website template:")
|
1085 |
+
st.code(website_template, language='html')
|
1086 |
+
|
1087 |
+
# نمایش کدهای CSS و JavaScript
|
1088 |
+
st.write("Displaying the CSS code:")
|
1089 |
+
st.code(css_code, language='css')
|
1090 |
+
|
1091 |
+
st.write("Displaying the JavaScript code:")
|
1092 |
+
st.code(js_code, language='javascript')
|
1093 |
+
|
1094 |
+
# نمایش تصاویر
|
1095 |
+
st.write("Displaying downloaded images:")
|
1096 |
+
for img_file in os.listdir(image_folder):
|
1097 |
+
img_path = os.path.join(image_folder, img_file)
|
1098 |
+
st.image(img_path, caption=f"Image: {img_file}")
|
1099 |
+
|
1100 |
+
# نمایش وبسایت
|
1101 |
+
st.write("Displaying the website:")
|
1102 |
+
with open('website_template.html', 'r', encoding='utf-8') as file:
|
1103 |
+
website_content = file.read()
|
1104 |
+
st.write(HTML(website_content))
|
1105 |
+
|
1106 |
+
|
1107 |
+
|
1108 |
+
|
1109 |
+
|
1110 |
+
|
1111 |
+
|
1112 |
+
|
1113 |
+
|
1114 |
+
|
1115 |
+
|
1116 |
+
|
1117 |
+
|
1118 |
|
1119 |
|
1120 |
|
|
|
1155 |
st.text_area("Chatbot's Response", value=chat , height=400)
|
1156 |
insert_chatbot_response(inp, chat)
|
1157 |
|
1158 |
+
a=logging.info(f"User input: {inp}, Chatbot response: {chat}")
|
1159 |
+
with open(LOG_FILE, 'r') as file:
|
1160 |
+
print(file.read())
|
1161 |
+
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
|
|
|
|
1167 |
|
1168 |
|
1169 |
except Exception as e:
|