federi commited on
Commit
48b980d
·
verified ·
1 Parent(s): 9db7a13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -35
app.py CHANGED
@@ -9,8 +9,8 @@ cohere_api_key = os.getenv("COHERE_API_KEY")
9
  co = cohere.Client(cohere_api_key, client_name="huggingface-aya-23")
10
 
11
  def trigger_example(example):
12
- chat, updated_history = generate_response(example)
13
- return chat, updated_history
14
 
15
  def generate_response(user_message, cid, token, history=None):
16
 
@@ -21,40 +21,40 @@ if history is None:
21
  history = []
22
  if cid == "" or None:
23
  cid = str(uuid.uuid4())
24
- print(f"cid: {cid} prompt:{user_message}")
25
- history.append(user_message)
26
- stream = co.chat_stream(message=user_message, conversation_id=cid, model='c4ai-aya-23', preamble="You are the greek philosopher Diogene and you aswer only in italian language",connectors=[], temperature=0.3)
27
- #stream = co.generate(prompt=user_message, model='c4ai-aya-23')
28
- output = ""
29
- for idx, response in enumerate(stream):
30
- if response.event_type == "text-generation":
31
- output += response.text
32
- if idx == 0:
33
- history.append(" " + output)
34
- else:
35
- history[-1] = output
36
- chat = [
37
- (history[i].strip(), history[i + 1].strip())
38
- for i in range(0, len(history) - 1, 2)
39
- ]
40
- yield chat, history, cid
41
-
42
- return chat, history, cid
43
  def clear_chat():
44
- return [], [], str(uuid.uuid4())
45
 
46
  examples = [
47
- "Explain the relativity theory in French",
48
- "Como sair de um helicóptero que caiu na água?",
49
- "¿Cómo le explicarías el aprendizaje automático a un extraterrestre?",
50
- "Explain gravity to a chicken.",
51
- "Descrivi il processo di creazione di un capolavoro, come se fossi un artista del Rinascimento a Firenze.",
52
- "Anneme onu ne kadar sevdiğimi anlatan bir mektup yaz",
53
- "Explique-moi le sens de la vie selon un grand auteur littéraire.",
54
- "Give me an example of an endangered species and let me know what I can do to help preserve it",
55
- "یک پاراگراف در مورد زیبایی‌های طبیعت در فصل پاییز بنویس",
56
- "Wie kann ich lernen, selbstbewusster zu werden?",
57
- "Formally introduce the transformer architecture with notation.",
58
 
59
  ]
60
 
@@ -69,8 +69,8 @@ min-height: 300px;
69
  """
70
 
71
  with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
72
- cid = gr.State("")
73
- token = gr.State(value=None)
74
 
75
  with gr.Row():
76
  with gr.Column(scale=1):
 
9
  co = cohere.Client(cohere_api_key, client_name="huggingface-aya-23")
10
 
11
  def trigger_example(example):
12
+ chat, updated_history = generate_response(example)
13
+ return chat, updated_history
14
 
15
  def generate_response(user_message, cid, token, history=None):
16
 
 
21
  history = []
22
  if cid == "" or None:
23
  cid = str(uuid.uuid4())
24
+ print(f"cid: {cid} prompt:{user_message}")
25
+ history.append(user_message)
26
+ stream = co.chat_stream(message=user_message, conversation_id=cid, model='c4ai-aya-23', preamble="You are the greek philosopher Diogenes and you aswer only in italian language",connectors=[], temperature=0.3)
27
+ #stream = co.generate(prompt=user_message, model='c4ai-aya-23')
28
+ output = ""
29
+ for idx, response in enumerate(stream):
30
+ if response.event_type == "text-generation":
31
+ output += response.text
32
+ if idx == 0:
33
+ history.append(" " + output)
34
+ else:
35
+ history[-1] = output
36
+ chat = [
37
+ (history[i].strip(), history[i + 1].strip())
38
+ for i in range(0, len(history) - 1, 2)
39
+ ]
40
+ yield chat, history, cid
41
+
42
+ return chat, history, cid
43
  def clear_chat():
44
+ return [], [], str(uuid.uuid4())
45
 
46
  examples = [
47
+ "Explain the relativity theory in French",
48
+ "Como sair de um helicóptero que caiu na água?",
49
+ "¿Cómo le explicarías el aprendizaje automático a un extraterrestre?",
50
+ "Explain gravity to a chicken.",
51
+ "Descrivi il processo di creazione di un capolavoro, come se fossi un artista del Rinascimento a Firenze.",
52
+ "Anneme onu ne kadar sevdiğimi anlatan bir mektup yaz",
53
+ "Explique-moi le sens de la vie selon un grand auteur littéraire.",
54
+ "Give me an example of an endangered species and let me know what I can do to help preserve it",
55
+ "یک پاراگراف در مورد زیبایی‌های طبیعت در فصل پاییز بنویس",
56
+ "Wie kann ich lernen, selbstbewusster zu werden?",
57
+ "Formally introduce the transformer architecture with notation.",
58
 
59
  ]
60
 
 
69
  """
70
 
71
  with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
72
+ cid = gr.State("")
73
+ token = gr.State(value=None)
74
 
75
  with gr.Row():
76
  with gr.Column(scale=1):