joaogante HF staff commited on
Commit
03844f7
·
1 Parent(s): 5265793
Files changed (2) hide show
  1. app.py +69 -22
  2. suggestions.py +0 -0
app.py CHANGED
@@ -1,6 +1,66 @@
1
  import gradio as gr
 
 
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  demo = gr.Blocks()
5
  with demo:
6
  gr.Markdown(
@@ -20,37 +80,23 @@ with demo:
20
  with gr.Row():
21
  with gr.Column():
22
  task_type = gr.Dropdown(
23
- label="Task Type",
24
- choices=[
25
- "✍️ Text Generation",
26
- "🤏 Summarization",
27
- "🫂 Translation",
28
- "💬 Conversational / Chatbot",
29
- "🕵️ (Table/Document/Visual/Text) Question Answering",
30
- "🎤 Automatic Speech Recognition",
31
- "🌇 Image to Text",
32
- ],
33
- value="Text Generation",
34
  interactive=True,
35
  )
36
  model_name = gr.Textbox(
37
- label="Which model are you using?",
38
- placeholder="google/flan-t5-xl",
39
  interactive=True,
40
  )
41
  problem_type = gr.Dropdown(
42
  label="What is your current problem?",
43
- choices=[
44
- "I would like a ChatGPT-like model",
45
- "The output is too repetitive",
46
- "The output is too short or too long",
47
- "Other"
48
- ],
49
- value="Text Generation",
50
  interactive=True,
51
  )
52
- get_suggestions = gr.Button(label="Get Suggestions!")
53
- with gr.Column(min_width=600):
54
  box = gr.Textbox()
55
 
56
  gr.Markdown(
@@ -59,6 +105,7 @@ with demo:
59
  [new discussion](https://huggingface.co/spaces/joaogante/generate_quality_improvement/discussions) 🙏
60
  """
61
  )
 
62
 
63
  if __name__ == "__main__":
64
  demo.launch()
 
1
  import gradio as gr
2
+ import huggingface_hub as hfh
3
+ from requests.exceptions import HTTPError
4
 
5
+ # =====================================================================================================================
6
+ # DATA
7
+ # =====================================================================================================================
8
+ # Dict with the tasks considered in this spaces, {pretty name: space tag}
9
+ TASK_TYPES = {
10
+ "✍️ Text Generation": "txtgen",
11
+ "🤏 Summarization": "summ",
12
+ "🫂 Translation": "trans",
13
+ "💬 Conversational / Chatbot": "chat",
14
+ "🤷 Text Question Answering": "txtqa",
15
+ "🕵️ (Table/Document/Visual) Question Answering": "otherqa",
16
+ "🎤 Automatic Speech Recognition": "asr",
17
+ "🌇 Image to Text": "img2txt",
18
+ }
19
 
20
+ # Dict matching all task types with their possible hub tags, {space tag: (possible hub tags)}
21
+ HUB_TAGS = {
22
+ "txtgen": ("text-generation", "text2text-generation"),
23
+ "summ": ("summarization", "text-generation", "text2text-generation"),
24
+ "trans": ("translation", "text-generation", "text2text-generation"),
25
+ "chat": ("conversational", "text-generation", "text2text-generation"),
26
+ "txtqa": ("text-generation", "text2text-generation"),
27
+ "otherqa": ("table-question-answering", "document-question-answering", "visual-question-answering"),
28
+ "asr": ("automatic-speech-recognition"),
29
+ "img2txt": ("image-to-text"),
30
+ }
31
+ assert len(TASK_TYPES) == len(TASK_TYPES)
32
+ assert all(tag in HUB_TAGS for tag in TASK_TYPES.values())
33
+
34
+ # Dict with the problems considered in this spaces, {problem: space tag}
35
+ PROBLEMS = {
36
+ "I would like a ChatGPT-like model": "chatgpt",
37
+ "The output is too repetitive": "repetitive",
38
+ "The output is too short": "short",
39
+ "Other": "show_all"
40
+ }
41
+
42
+ # =====================================================================================================================
43
+
44
+
45
+ # =====================================================================================================================
46
+ # SUGGESTIONS LOGIC
47
+ # =====================================================================================================================
48
+ def is_valid_task_for_model(model_name, task_type):
49
+ if model_name == "":
50
+ return True
51
+ try:
52
+ model_tags = hfh.HfApi().model_info(model_name).tags
53
+ except HTTPError:
54
+ return True # Assume everything is okay
55
+
56
+ possible_tags = HUB_TAGS[TASK_TYPES[task_type]]
57
+ return any(tag in model_tags for tag in possible_tags)
58
+ # =====================================================================================================================
59
+
60
+
61
+ # =====================================================================================================================
62
+ # GRADIO
63
+ # =====================================================================================================================
64
  demo = gr.Blocks()
65
  with demo:
66
  gr.Markdown(
 
80
  with gr.Row():
81
  with gr.Column():
82
  task_type = gr.Dropdown(
83
+ label="What is the task you're trying to accomplish?",
84
+ choices=list(TASK_TYPES.keys()),
85
+ value=TASK_TYPES[0],
 
 
 
 
 
 
 
 
86
  interactive=True,
87
  )
88
  model_name = gr.Textbox(
89
+ label="Which model are you using? (leave blank if you haven't decided)",
90
+ placeholder="e.g. google/flan-t5-xl",
91
  interactive=True,
92
  )
93
  problem_type = gr.Dropdown(
94
  label="What is your current problem?",
95
+ choices=list(PROBLEMS.keys()),
 
 
 
 
 
 
96
  interactive=True,
97
  )
98
+ get_suggestions = gr.Button(value="Get Suggestions!")
99
+ with gr.Column(scale=2):
100
  box = gr.Textbox()
101
 
102
  gr.Markdown(
 
105
  [new discussion](https://huggingface.co/spaces/joaogante/generate_quality_improvement/discussions) 🙏
106
  """
107
  )
108
+ # =====================================================================================================================
109
 
110
  if __name__ == "__main__":
111
  demo.launch()
suggestions.py ADDED
File without changes