cccmatthew commited on
Commit
7b875b3
1 Parent(s): a25709c

Remove streamlit

Browse files
Files changed (1) hide show
  1. inference.py +5 -13
inference.py CHANGED
@@ -1,10 +1,6 @@
1
- import streamlit as st
2
  import requests
3
- import csv
4
- import datetime
5
  import time
6
  import pandas as pd
7
- import matplotlib.pyplot as plt
8
  import os
9
 
10
  ##########################
@@ -13,11 +9,6 @@ headers = {"Authorization": "Bearer " + SECRET}
13
  API_URL = "https://api-inference.huggingface.co/models/cccmatthew/surrey-gp30"
14
  ##########################
15
 
16
- def log_to_csv(sentence, results, response_time):
17
- with open('model_interactions.csv', 'a', newline='') as file:
18
- writer = csv.writer(file)
19
- writer.writerow([datetime.datetime.now(), sentence, results, response_time])
20
-
21
  def send_request_with_retry(url, headers, json_data, retries=3, backoff_factor=1):
22
  """Send request with retries on timeouts and HTTP 503 errors."""
23
  for attempt in range(retries):
@@ -29,14 +20,14 @@ def send_request_with_retry(url, headers, json_data, retries=3, backoff_factor=1
29
  return response, response_time
30
  except requests.exceptions.HTTPError as e:
31
  if response.status_code == 503:
32
- st.info('Server is unavailable, retrying...')
33
  else:
34
  raise
35
  except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
36
- st.info(f"Network issue ({str(e)}), retrying...")
37
  time.sleep(backoff_factor * (2 ** attempt))
38
 
39
- st.error("Failed to process request after several attempts.")
40
  return None, None
41
 
42
  sentence = [
@@ -52,6 +43,7 @@ response, response_time = send_request_with_retry(API_URL, headers, {"inputs": s
52
  if response is not None:
53
  results = response.json()
54
  print(results)
 
55
 
56
  else:
57
- st.error("Unable to classify the sentence due to server issues.")
 
 
1
  import requests
 
 
2
  import time
3
  import pandas as pd
 
4
  import os
5
 
6
  ##########################
 
9
  API_URL = "https://api-inference.huggingface.co/models/cccmatthew/surrey-gp30"
10
  ##########################
11
 
 
 
 
 
 
12
  def send_request_with_retry(url, headers, json_data, retries=3, backoff_factor=1):
13
  """Send request with retries on timeouts and HTTP 503 errors."""
14
  for attempt in range(retries):
 
20
  return response, response_time
21
  except requests.exceptions.HTTPError as e:
22
  if response.status_code == 503:
23
+ print('Server is unavailable, retrying...')
24
  else:
25
  raise
26
  except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
27
+ print(f"Network issue ({str(e)}), retrying...")
28
  time.sleep(backoff_factor * (2 ** attempt))
29
 
30
+ print("Failed to process request after several attempts.")
31
  return None, None
32
 
33
  sentence = [
 
43
  if response is not None:
44
  results = response.json()
45
  print(results)
46
+ response.close()
47
 
48
  else:
49
+ print("Unable to classify the sentence due to server issues.")