camparchimedes commited on
Commit
e1f6cb1
β€’
1 Parent(s): 72faeb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -15
app.py CHANGED
@@ -1,12 +1,10 @@
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("HuggingFaceH4/zephyr-7b-beta")
8
 
9
-
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -14,6 +12,7 @@ def respond(
14
  max_tokens,
15
  temperature,
16
  top_p,
 
17
  ):
18
  messages = [{"role": "system", "content": system_message}]
19
 
@@ -39,21 +38,44 @@ def respond(
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(
49
- value="""예의 λ°”λ₯΄κ²Œ ν•˜μ„Έμš”, μΉœμ ˆν•˜κ²Œ ν•˜μ„Έμš”,κ°„κ²°ν•˜κ²Œ ν•˜μ„Έμš”,λͺ…ν™•ν•˜κ²Œ ν•˜μ„Έμš”,λ©‹μ§€κ²Œ ν•˜μ„Έμš”,μ „λ¬Έκ°€μ²˜λŸΌ ν•˜μ„Έμš”.You are Nixie Steamcore, a hotbot!""",
50
- label="System message"
51
- ),
52
- gr.Textbox(value="Analyze and extract information from text.", label="Analyze and extract information from text."),
53
- gr.Textbox(value="Provide definitions, facts, and examples in response to questions.", label="Provide definitions, facts, and examples in response to questions."),
54
- gr.Textbox(value="Write articles, essays, and other text based on given prompts.", label="Write articles, essays, and other text based on given prompts."),
55
- gr.Textbox(value="Create creative responses such as stories, memes, and jokes.", label="Generate creative responses to prompts, such as stories, memes, and jokes."),
56
- gr.Textbox(value="Collaborate to make databases, knowledge repositories, and exercises.", label="Collaborate to make databases, knowledge repositories, and exercises."),
57
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
58
  gr.Slider(minimum=0.1, maximum=4.0, value=1.2, step=0.1, label="Temperature"),
59
  gr.Slider(
@@ -63,9 +85,10 @@ demo = gr.ChatInterface(
63
  step=0.05,
64
  label="Top-p (nucleus sampling)",
65
  ),
 
66
  ],
67
  )
68
 
69
-
70
  if __name__ == "__main__":
71
  demo.launch()
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import pandas as pd
4
+ import json
5
 
 
 
 
6
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
7
 
 
8
  def respond(
9
  message,
10
  history: list[tuple[str, str]],
 
12
  max_tokens,
13
  temperature,
14
  top_p,
15
+ uploaded_file,
16
  ):
17
  messages = [{"role": "system", "content": system_message}]
18
 
 
38
  response += token
39
  yield response
40
 
41
+ # Process the uploaded file if any
42
+ if uploaded_file is not None:
43
+ print(f"Uploaded file: {uploaded_file.name}")
44
+
45
+ # Process a CSV file
46
+ if uploaded_file.name.endswith(".csv"):
47
+ try:
48
+ df = pd.read_csv(uploaded_file.name)
49
+ print(f"CSV file loaded with {len(df)} rows and {len(df.columns)} columns.")
50
+ json_data = df.to_json(orient="records")
51
+ with open(f"{uploaded_file.name.split('.')[0]}.json", "w") as json_file:
52
+ json_file.write(json_data)
53
+ print(f"JSON file created: {uploaded_file.name.split('.')[0]}.json")
54
+ except Exception as e:
55
+ print(f"Error loading CSV file: {e}")
56
+
57
+ # Process a text file
58
+ elif uploaded_file.name.endswith(".txt"):
59
+ try:
60
+ with open(uploaded_file.name, "r") as f:
61
+ text = f.read()
62
+ print(f"Text file loaded with {len(text)} characters.")
63
+ json_data = json.dumps({"text": text})
64
+ with open(f"{uploaded_file.name.split('.')[0]}.json", "w") as json_file:
65
+ json_file.write(json_data)
66
+ print(f"JSON file created: {uploaded_file.name.split('.')[0]}.json")
67
+ except Exception as e:
68
+ print(f"Error loading text file: {e}")
69
+
70
+ # Add more file type checks and processing logic as needed
71
+
72
  """
73
+ For information on how to customize the ChatInterface: https://www.gradio.app/docs/chatinterface
74
  """
75
  demo = gr.ChatInterface(
76
  respond,
77
+ title="Nixie Steamcore, a hotbot!",
78
  additional_inputs=[
 
 
 
 
 
 
 
 
 
79
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
80
  gr.Slider(minimum=0.1, maximum=4.0, value=1.2, step=0.1, label="Temperature"),
81
  gr.Slider(
 
85
  step=0.05,
86
  label="Top-p (nucleus sampling)",
87
  ),
88
+ gr.File(label="Upload a document"),
89
  ],
90
  )
91
 
 
92
  if __name__ == "__main__":
93
  demo.launch()
94
+