abubasith86 commited on
Commit
0d944ef
·
1 Parent(s): cd2ca57
Files changed (1) hide show
  1. app.py +31 -3
app.py CHANGED
@@ -9,15 +9,44 @@ For more information on `huggingface_hub` Inference API support, please check th
9
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
10
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def respond(
13
  message,
14
  history: list[tuple[str, str]],
15
- system_message,
16
  max_tokens,
17
  temperature,
18
  top_p,
19
  ):
20
- messages = [{"role": "system", "content": system_message}]
21
 
22
  for val in history:
23
  if val[0]:
@@ -48,7 +77,6 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
48
  demo = gr.ChatInterface(
49
  respond,
50
  additional_inputs=[
51
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
52
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
53
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
54
  gr.Slider(
 
9
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
10
 
11
 
12
+ # PDF Parsing
13
+ def extract_text_from_pdf(pdf_file):
14
+ doc = pymupdf.open(pdf_file)
15
+ text = " ".join([page.get_textpage().extractTEXT() for page in doc])
16
+ return text
17
+
18
+
19
+ # Web search fallback
20
+ def search_web(query):
21
+ with DDGS() as ddgs:
22
+ results = ddgs.text(query)
23
+ if results:
24
+ return results[0]["body"]
25
+ return "No relevant results found on the web."
26
+
27
+
28
+ SYSTEM_PROMPT = """
29
+ You are an intelligent and friendly AI assistant.
30
+
31
+ Your goals:
32
+ - Answer user questions clearly and concisely.
33
+ - If a PDF document is provided, use its content to give informed answers.
34
+ - For questions about recent or live topics (e.g., news, prices, events), you may perform a web search and summarize the result.
35
+ - If no document or web context is available, still try to help using general knowledge.
36
+ - Be honest if you don’t know something.
37
+ - Always be polite, helpful, and respectful.
38
+
39
+ """
40
+
41
+
42
  def respond(
43
  message,
44
  history: list[tuple[str, str]],
 
45
  max_tokens,
46
  temperature,
47
  top_p,
48
  ):
49
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
50
 
51
  for val in history:
52
  if val[0]:
 
77
  demo = gr.ChatInterface(
78
  respond,
79
  additional_inputs=[
 
80
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
81
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
82
  gr.Slider(