Spaces:
openfree
/
Running on CPU Upgrade

seawolf2357 commited on
Commit
ab30506
ยท
verified ยท
1 Parent(s): a1ccc70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -59
app.py CHANGED
@@ -1,63 +1,45 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("CohereForAI/c4ai-command-r-plus-08-2024")
8
-
9
-
10
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
13
- system_message,
14
- max_tokens,
15
- temperature,
16
- top_p,
17
- ):
18
- messages = [{"role": "system", "content": system_message}]
19
-
20
- for val in history:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
-
26
- messages.append({"role": "user", "content": message})
27
-
28
- response = ""
29
-
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
-
39
- response += token
40
- yield response
41
-
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
- demo = gr.ChatInterface(
46
- respond,
47
- additional_inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
- gr.Slider(
52
- minimum=0.1,
53
- maximum=1.0,
54
- value=0.95,
55
- step=0.05,
56
- label="Top-p (nucleus sampling)",
57
- ),
58
  ],
 
 
 
59
  )
60
 
61
-
62
- if __name__ == "__main__":
63
- demo.launch()
 
1
  import gradio as gr
2
+ from gnewsclient import gnewsclient
3
+ from datetime import datetime, timedelta
4
+
5
+ # Google ๋‰ด์Šค ํด๋ผ์ด์–ธํŠธ ์ดˆ๊ธฐํ™”
6
+ client = gnewsclient.NewsClient()
7
+
8
+ # ์ง€์›๋˜๋Š” ๊ตญ๊ฐ€ ๋ชฉ๋ก
9
+ supported_countries = client.locations
10
+
11
+ def get_news(country, keyword):
12
+ # ๊ตญ๊ฐ€ ์„ค์ •
13
+ client.location = country
14
+ client.language = 'en' # ์˜์–ด๋กœ ์„ค์ •
15
+
16
+ # ํ˜„์žฌ ์‹œ๊ฐ„ ๊ธฐ์ค€ 24์‹œ๊ฐ„ ์ „ ์‹œ๊ฐ„ ๊ณ„์‚ฐ
17
+ time_threshold = datetime.now() - timedelta(hours=24)
18
+
19
+ # ๋‰ด์Šค ๊ฒ€์ƒ‰
20
+ news_items = client.get_news(keyword)
21
+
22
+ # 24์‹œ๊ฐ„ ์ด๋‚ด์˜ ๋‰ด์Šค๋งŒ ํ•„ํ„ฐ๋งํ•˜๊ณ  ์ œ๋ชฉ๊ณผ ๋งํฌ ์ถ”์ถœ
23
+ filtered_news = []
24
+ for item in news_items:
25
+ if 'published' in item:
26
+ news_date = datetime.strptime(item['published'], "%a, %d %b %Y %H:%M:%S %Z")
27
+ if news_date > time_threshold:
28
+ filtered_news.append(f"Title: {item['title']}\nLink: {item['link']}\n")
29
+
30
+ return "\n".join(filtered_news) if filtered_news else "No recent news found for the given keyword."
31
+
32
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
33
+ iface = gr.Interface(
34
+ fn=get_news,
35
+ inputs=[
36
+ gr.Dropdown(choices=supported_countries, label="Select Country"),
37
+ gr.Textbox(label="Enter keyword")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  ],
39
+ outputs="text",
40
+ title="Google News Search",
41
+ description="Search for news articles from the last 24 hours using Google News."
42
  )
43
 
44
+ # ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
45
+ iface.launch()