wop commited on
Commit
cd93ac8
·
verified ·
1 Parent(s): 1e31df6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,27 +1,30 @@
1
  import streamlit as st
2
- import requests
3
- import json
4
- import time
5
 
6
  # Load data.json
7
  with open('data.json') as f:
8
  data = json.load(f)
9
 
10
- client_endpoint = "https://olivier-truong-mistral-super-fast.hf.space/chat"
11
 
12
  def ask_question(question):
13
  if question in data:
14
  return data[question]
15
  else:
16
- response = requests.post(client_endpoint, json={"context": question})
17
- if response.status_code == 200:
18
- answer = response.json()['response']
19
- data[question] = answer
20
- with open('data.json', 'w') as f:
21
- json.dump(data, f)
22
- return answer
23
- else:
24
- return "Error: Failed to retrieve an answer."
 
 
 
 
 
25
 
26
  def typewriter(text: str, speed: int):
27
  tokens = text.split()
 
1
  import streamlit as st
2
+ from gradio_client import Client
 
 
3
 
4
  # Load data.json
5
  with open('data.json') as f:
6
  data = json.load(f)
7
 
8
+ client_endpoint = "https://olivier-truong-mistral-super-fast.hf.space/"
9
 
10
  def ask_question(question):
11
  if question in data:
12
  return data[question]
13
  else:
14
+ client = Client(client_endpoint)
15
+ result = client.predict(
16
+ question,
17
+ 0.9, # Temperature
18
+ 2000, # Max new tokens
19
+ 0.9, # Top-p (nucleus sampling)
20
+ 1.2, # Repetition penalty
21
+ api_name="/chat"
22
+ )
23
+ answer = result["data"]
24
+ data[question] = answer
25
+ with open('data.json', 'w') as f:
26
+ json.dump(data, f)
27
+ return answer
28
 
29
  def typewriter(text: str, speed: int):
30
  tokens = text.split()