Petzys commited on
Commit
71e901c
·
1 Parent(s): 687c737

test: added testcase for test_get_id_from_string

Browse files
Files changed (5) hide show
  1. .gitignore +1 -0
  2. app.py +25 -26
  3. requirements.txt +1 -0
  4. test/test_app.py +0 -12
  5. test_app.py +15 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__
app.py CHANGED
@@ -130,30 +130,29 @@ EXPLANATION
130
 
131
  return out_text
132
 
133
- # --- UI ---
134
- with gr.Blocks(theme='gstaff/xkcd') as demo:
135
- gr.Markdown("# xkcd Comic Finder")
136
- gr.Markdown(
137
- "Sign in with your Hugging Face account so the app can call the model via the Inference API."
138
- "\n\n> If you deploy to a Space, add `hf_oauth: true` in your Space metadata and grant the `inference:api` scope."
139
- )
140
- gr.LoginButton() # Shows “Sign in with Hugging Face”
141
-
142
- gr.ChatInterface(
143
- fn=respond,
144
- title="xkcd Comic Finder",
145
- description="Find the most suitable xkcd comic for your situation. Use the login button above.",
146
- examples=[
147
- "I need a comic about procrastination.",
148
- "A comic for programmers debugging code.",
149
- "Life advice in comic form.",
150
- ],
151
- type="messages",
152
- )
153
-
154
  if __name__ == "__main__":
155
- global index
156
- global meta
157
- index, meta = get_index()
158
- embedder = SentenceTransformer("all-MiniLM-L6-v2")
159
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  return out_text
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  if __name__ == "__main__":
134
+ # --- UI ---
135
+ with gr.Blocks(theme='gstaff/xkcd') as demo:
136
+ gr.Markdown("# xkcd Comic Finder")
137
+ gr.Markdown(
138
+ "Sign in with your Hugging Face account so the app can call the model via the Inference API."
139
+ "\n\n> If you deploy to a Space, add `hf_oauth: true` in your Space metadata and grant the `inference:api` scope."
140
+ )
141
+ gr.LoginButton() # Shows “Sign in with Hugging Face”
142
+
143
+ gr.ChatInterface(
144
+ fn=respond,
145
+ title="xkcd Comic Finder",
146
+ description="Find the most suitable xkcd comic for your situation. Use the login button above.",
147
+ examples=[
148
+ "I need a comic about procrastination.",
149
+ "A comic for programmers debugging code.",
150
+ "Life advice in comic form.",
151
+ ],
152
+ type="messages",
153
+ )
154
+ global index
155
+ global meta
156
+ index, meta = get_index()
157
+ embedder = SentenceTransformer("all-MiniLM-L6-v2")
158
+ demo.launch()
requirements.txt CHANGED
@@ -3,3 +3,4 @@ faiss-cpu
3
  transformers
4
  sentence-transformers
5
  datasets
 
 
3
  transformers
4
  sentence-transformers
5
  datasets
6
+ gradio[oauth]
test/test_app.py DELETED
@@ -1,12 +0,0 @@
1
- import pytest
2
- from app import build_index, respond
3
-
4
- def test_build_index():
5
- index, meta = build_index()
6
- assert index is not None
7
- assert meta is not None
8
-
9
- def test_respond():
10
- respond("I need a comic about procrastination.")
11
- assert response is str
12
-
 
 
 
 
 
 
 
 
 
 
 
 
 
test_app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import unittest
2
+
3
+ from app import get_id_from_string
4
+
5
+ class TestGetIdFromString(unittest.TestCase):
6
+ def test_get_id_from_string(self):
7
+ test_string = """
8
+ [844] https://xkcd.com/844/
9
+
10
+ This comic fits best because it directly addresses the topic of programmers debugging code, specifically the challenges and frustrations that come with it. The comic's flowchart and accompanying text poke fun at the common experience of programmers struggling to write good code, and the inevitable cycle of rewriting and restarting that often ensues.
11
+ """
12
+ self.assertEqual(get_id_from_string(test_string), "844")
13
+
14
+ if __name__ == "__main__":
15
+ unittest.main()