Manavraj commited on
Commit
8c537bd
·
verified ·
1 Parent(s): 5d17291

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -9
app.py CHANGED
@@ -1,33 +1,71 @@
1
  import gradio as gr
2
 
3
- def search_knowledge_base(issue: str) -> str:
4
  """
5
  Search the knowledge base for solutions related to the provided issue.
 
 
 
 
6
  """
7
- if "wifi" in issue.lower():
 
8
  return "Check if your router is powered on. Restart your router. Try connecting again."
9
- elif "screen" in issue.lower():
10
  return "Adjust display cable. Update graphics drivers. Restart the system."
11
  return "No predefined solution found in the knowledge base."
12
 
13
- def search_web(query: str) -> str:
14
  """
15
  Perform a simulated web search for the given query.
 
 
 
 
16
  """
17
  return f"(Simulated Web Result) Top search result for '{query}'."
18
 
19
- def format_response(raw_steps: str) -> str:
20
  """
21
  Format the raw steps into a numbered list.
 
 
 
 
22
  """
23
  steps = raw_steps.split(". ")
24
  steps = [f"{i+1}. {step.strip('.')}" for i, step in enumerate(steps) if step.strip()]
25
  return "\n".join(steps)
26
 
27
- with gr.Blocks() as demo:
28
- gr.Interface(fn=search_knowledge_base, inputs="text", outputs="text", title="Knowledge Base Search")
29
- gr.Interface(fn=search_web, inputs="text", outputs="text", title="Web Search")
30
- gr.Interface(fn=format_response, inputs="text", outputs="text", title="Response Formatter")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  if __name__ == "__main__":
33
  demo.launch(share=True)
 
1
  import gradio as gr
2
 
3
+ def search_knowledge_base(issue):
4
  """
5
  Search the knowledge base for solutions related to the provided issue.
6
+ Args:
7
+ issue (str): The technical issue to search for
8
+ Returns:
9
+ str: Solution steps or message if no solution found
10
  """
11
+ issue = issue.lower()
12
+ if "wifi" in issue:
13
  return "Check if your router is powered on. Restart your router. Try connecting again."
14
+ elif "screen" in issue:
15
  return "Adjust display cable. Update graphics drivers. Restart the system."
16
  return "No predefined solution found in the knowledge base."
17
 
18
+ def search_web(query):
19
  """
20
  Perform a simulated web search for the given query.
21
+ Args:
22
+ query (str): The search query
23
+ Returns:
24
+ str: Simulated search results
25
  """
26
  return f"(Simulated Web Result) Top search result for '{query}'."
27
 
28
+ def format_response(raw_steps):
29
  """
30
  Format the raw steps into a numbered list.
31
+ Args:
32
+ raw_steps (str): Raw text steps separated by periods
33
+ Returns:
34
+ str: Formatted numbered list of steps
35
  """
36
  steps = raw_steps.split(". ")
37
  steps = [f"{i+1}. {step.strip('.')}" for i, step in enumerate(steps) if step.strip()]
38
  return "\n".join(steps)
39
 
40
+ # Knowledge Base Search Interface
41
+ demo1 = gr.Interface(
42
+ fn=search_knowledge_base,
43
+ inputs=[gr.Textbox("wifi connection problem")],
44
+ outputs=[gr.Textbox()],
45
+ title="Knowledge Base Search",
46
+ description="Enter a technical issue to search for solutions in the knowledge base."
47
+ )
48
+
49
+ # Web Search Interface
50
+ demo2 = gr.Interface(
51
+ fn=search_web,
52
+ inputs=[gr.Textbox("latest tech news")],
53
+ outputs=[gr.Textbox()],
54
+ title="Web Search",
55
+ description="Enter a search query to get simulated web search results."
56
+ )
57
+
58
+ # Response Formatter Interface
59
+ demo3 = gr.Interface(
60
+ fn=format_response,
61
+ inputs=[gr.Textbox("Step one. Step two. Step three")],
62
+ outputs=[gr.Textbox()],
63
+ title="Response Formatter",
64
+ description="Enter raw steps separated by periods to format them as a numbered list."
65
+ )
66
+
67
+ # Combine all interfaces using Tabs (following demo pattern)
68
+ demo = gr.TabbedInterface([demo1, demo2, demo3], ["Knowledge Base", "Web Search", "Formatter"])
69
 
70
  if __name__ == "__main__":
71
  demo.launch(share=True)