mehmet0001 commited on
Commit
3567445
·
verified ·
1 Parent(s): 1e81754

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -29
app.py CHANGED
@@ -4,17 +4,20 @@ import create_database
4
  import streamlit as st
5
 
6
  api_key = "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"
 
7
 
8
- config = st.text_area("Enter the start URL and the limit of crawling (in this format : URL,limit):")
9
- config_btn = st.button("Start crawling!")
 
10
 
11
- if config and config_btn:
12
- start = config.split(",")[0]
13
- limit = int(config.split(",")[1])
14
-
15
- txt = crawl_the_site.crawl(start,limit)
16
- st.session_state.collection = create_database.create_database(txt)
17
- st.write("Crawling is done")
 
18
 
19
  openai_client = OpenAI(base_url="https://openrouter.ai/api/v1",api_key=api_key)
20
 
@@ -25,24 +28,25 @@ prompt_template = """Answer the question only according to the information provi
25
  ## Question :
26
  # {}"""
27
 
28
- prompt = st.chat_input("What would you like to chat about?")
29
- prompt_btn = st.button("Enter")
30
-
31
- if prompt and prompt_btn:
32
- results = st.session_state.collection.query(query_texts=[prompt],n_results=5)
33
- infos = results["documents"][0]
34
-
35
- info_text = ""
36
- for info in infos:
37
- info_text += info + "\n---\n"
38
- info_text = info_text.strip()
39
-
40
- prompt = prompt_template.format(info_text,prompt)
41
-
42
- completion = openai_client.chat.completions.create(
43
- extra_headers={},
44
- extra_body={},
45
- model="deepseek/deepseek-r1:free",
46
- messages=[{"role":"user","content":prompt}])
47
 
48
- st.write((completion.choices[0].message.content)[7:-1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import streamlit as st
5
 
6
  api_key = "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"
7
+ st.session_state.stage = "crawl-input"
8
 
9
+ if st.session_state.stage == "crawl-input":
10
+ config = st.text_area("Enter the start URL and the limit of crawling (in this format : URL,limit):")
11
+ config_btn = st.button("Start crawling!")
12
 
13
+ if config and config_btn:
14
+ start = config.split(",")[0]
15
+ limit = int(config.split(",")[1])
16
+
17
+ txt = crawl_the_site.crawl(start,limit)
18
+ st.session_state.collection = create_database.create_database(txt)
19
+ st.write("Crawling is done")
20
+ st.session_state.stage = "prompt-input"
21
 
22
  openai_client = OpenAI(base_url="https://openrouter.ai/api/v1",api_key=api_key)
23
 
 
28
  ## Question :
29
  # {}"""
30
 
31
+ if st.session_state.stage == "prompt-input"
32
+ prompt = st.chat_input("What would you like to chat about?")
33
+ prompt_btn = st.button("Enter")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
+ if prompt and prompt_btn:
36
+ results = st.session_state.collection.query(query_texts=[prompt],n_results=5)
37
+ infos = results["documents"][0]
38
+
39
+ info_text = ""
40
+ for info in infos:
41
+ info_text += info + "\n---\n"
42
+ info_text = info_text.strip()
43
+
44
+ prompt = prompt_template.format(info_text,prompt)
45
+
46
+ completion = openai_client.chat.completions.create(
47
+ extra_headers={},
48
+ extra_body={},
49
+ model="deepseek/deepseek-r1:free",
50
+ messages=[{"role":"user","content":prompt}])
51
+
52
+ st.write((completion.choices[0].message.content)[7:-1])