merve HF staff commited on
Commit
19d6ff0
β€’
1 Parent(s): 3ae724c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -14,7 +14,24 @@ def query(payload):
14
  return response.json(), response
15
 
16
 
17
- context = "To extract information from documents, use sentence similarity task. To do sentiment analysis from tweets, use text classification task. To detect masks from images, use object detection task. To extract information from invoices, use named entity recognition from token classification task."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  message_history = [{"text":"Let's find out the best task for your use case! Tell me about your use case :)", "is_user":False}]
@@ -38,13 +55,24 @@ data, resp = query(
38
  }
39
  }
40
  )
 
 
41
  if resp.status_code == 200:
42
 
43
  model_answer = data["answer"]
44
- response_templates = [f"{model_answer} is the best task for this 🀩", f"I think you should use {model_answer} πŸͺ„", f"I think {model_answer} should work for you πŸ€“"]
 
 
 
 
45
 
46
- bot_answer = random.choice(response_templates)
47
- message_history.append({"text":bot_answer, "is_user" : False})
 
 
 
 
 
48
 
49
  with placeholder.container():
50
  last_message = message_history[-1]
 
14
  return response.json(), response
15
 
16
 
17
+ context = "To extract information from documents, use sentence similarity task. To do sentiment analysis from tweets, use text classification task. To detect masks from images, use object detection task. To extract name or address from documents, use named entity recognition from token classification task. To build voice enabled applications, you can use automatic speech recognition. You can retrieve information from documents using sentence similarity models. You can summarize papers using summarization models. You can convert text to speech using text-to-speech task. To detect language spoken in an audio, you can use audio classification task. To detect emotion in an audio, you can use audio classification task. To detect commands in an audio, you can use audio classification task. To decompose sounds in a recording, use audio-to-audio task. To answer questions from a document, you can use question answering task. To answer FAQs from your customers, you can use question answering. To see if a text is grammatically correct, you can use text classification. To augment your training data, you can use text classification. For pedestrian detection, you can use object detection."
18
+
19
+
20
+ link_dict = {
21
+ "audio-to-audio": "https://huggingface.co/tasks/audio-to-audio",
22
+ "audio classification": "https://huggingface.co/tasks/audio-classification",
23
+ "automatic speech recognition": "https://huggingface.co/tasks/automatic-speech-recognition",
24
+ "fill-mask":"https://huggingface.co/tasks/fill-mask",
25
+ "question answering":"https://huggingface.co/tasks/question-answering",
26
+ "text-to-speech":"https://huggingface.co/tasks/text-to-speech",
27
+ "sentence similarity": "https://huggingface.co/tasks/sentence-similarity",
28
+ "summarization":"https://huggingface.co/tasks/summarization",
29
+ "text generation": "https://huggingface.co/tasks/text-generation",
30
+ "translation": "https://huggingface.co/tasks/translation",
31
+ "image classification": "https://huggingface.co/tasks/image-classification",
32
+ "image segmentation": "https://huggingface.co/tasks/image-segmentation",
33
+ "object detection": "https://huggingface.co/tasks/object-detection"}
34
+
35
 
36
 
37
  message_history = [{"text":"Let's find out the best task for your use case! Tell me about your use case :)", "is_user":False}]
 
55
  }
56
  }
57
  )
58
+
59
+
60
  if resp.status_code == 200:
61
 
62
  model_answer = data["answer"]
63
+ for key in link_dict:
64
+ if key in model_answer:
65
+ link_dict[key] = url
66
+ response_templates = [f"{model_answer} is the best task for this 🀩 Check out the page πŸ‘‰πŸΌ {url}", f"I think you should use {model_answer} πŸͺ„ Check it out here πŸ‘‰πŸΌ {url}", f"I think {model_answer} should work for you πŸ€“ Check out the page πŸ‘‰πŸΌ {url}"]
67
+
68
 
69
+ bot_answer = random.choice(response_templates)
70
+ message_history.append({"text":bot_answer, "is_user" : False})
71
+ else:
72
+ fallback_template = ["I didn't get the question 🧐 Could you please ask again? Try 'What should I use for detecting masks in an image?'",
73
+ "Hmm, not sure I know the answer, maybe you could ask differently? πŸ€“",
74
+ "Sorry, I didn't understand you, maybe you could ask differently? πŸ€“ Try asking 'What should I use to extract name in a document' πŸ€—"]
75
+ bot_answer = random.choice(fallback_template)
76
 
77
  with placeholder.container():
78
  last_message = message_history[-1]