vagrillo commited on
Commit
3e39051
·
verified ·
1 Parent(s): 36a7465

Update app.py

Browse files

from facebook_scraper import get_posts
for post in get_posts('nintendo', pages=1):
print(post['text'][:50])

Files changed (1) hide show
  1. app.py +3 -63
app.py CHANGED
@@ -1,63 +1,3 @@
1
- from huggingface_hub import InferenceClient
2
- import gradio as gr
3
-
4
- client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
5
-
6
- def format_prompt(message, history):
7
- prompt = "<s>"
8
- for user_prompt, bot_response in history:
9
- prompt += f"[INST] {user_prompt} [/INST]"
10
- prompt += f" {bot_response}</s> "
11
- prompt += f"[INST] {message} [/INST]"
12
- return prompt
13
-
14
- def generate(
15
- prompt, history, temperature=0.5, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0,
16
- ):
17
- temperature = float(temperature)
18
- if temperature < 1e-2:
19
- temperature = 1e-2
20
- top_p = float(top_p)
21
-
22
- generate_kwargs = dict(
23
- temperature=temperature,
24
- max_new_tokens=max_new_tokens,
25
- top_p=top_p,
26
- repetition_penalty=repetition_penalty,
27
- do_sample=True,
28
- seed=42,
29
- )
30
-
31
- formatted_prompt = format_prompt(prompt, history)
32
-
33
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
34
- output = ""
35
-
36
- for response in stream:
37
- output += response.token.text
38
- yield output
39
- return output
40
-
41
-
42
- additional_inputs=[
43
- gr.Slider(
44
- label="Temperature",
45
- value=0.9,
46
- minimum=0.0,
47
- maximum=1.0,
48
- step=0.05,
49
- interactive=True,
50
- info="Higher values generate more diverse outputs",
51
- )
52
- ]
53
-
54
- bbchatbot = gr.Chatbot(
55
- avatar_images=["./user.png", "./bot.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
56
-
57
- demo = gr.ChatInterface(fn=generate,
58
- chatbot=bbchatbot,
59
- title="🫐TheBlueberry-AI's Chat with Mistral 7B v0.2🪄",
60
- additional_inputs=additional_inputs
61
- )
62
-
63
- demo.queue().launch()
 
1
+ from facebook_scraper import get_posts
2
+ for post in get_posts('nintendo', pages=1):
3
+ print(post['text'][:50])