Spaces:
Runtime error
Runtime error
on1onmangoes
commited on
Commit
•
5c6a6e5
1
Parent(s):
16963ae
Update app.py
Browse files
app.py
CHANGED
@@ -6,12 +6,7 @@ import os
|
|
6 |
HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
|
7 |
|
8 |
# Initialize the Gradio Client for the specified API
|
9 |
-
#client = Client("on1onmangoes/CNIHUB10724v10", hf_token=HF_TOKEN)
|
10 |
client = Client("on1onmangoes/CNIHUB101324v10", hf_token=HF_TOKEN)
|
11 |
-
# on1onmangoes/CNIHUB101324v10
|
12 |
-
|
13 |
-
|
14 |
-
# Here's how you can fix it:
|
15 |
|
16 |
# Update the conversation history within the function.
|
17 |
# Return the updated history along with any other required outputs.
|
@@ -77,53 +72,16 @@ def format_answer_string(answer: str):
|
|
77 |
# Step 2: Clean up formatting by replacing escaped newline characters
|
78 |
formatted_answer = answer_before_docs.replace("\\n", "\n").strip()
|
79 |
|
80 |
-
# Step 3:
|
81 |
-
|
82 |
-
if formatted_answer.startswith("('") and formatted_answer.endswith("',"):
|
83 |
formatted_answer = formatted_answer[2:-2].strip()
|
84 |
|
85 |
-
# Optional: Add a prefix
|
86 |
formatted_answer = "Co-Pilot: " + formatted_answer
|
87 |
|
88 |
return formatted_answer
|
89 |
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
# this version works just issue with formatting
|
94 |
-
# def stream_chat_with_rag(
|
95 |
-
# message: str,
|
96 |
-
# history: list,
|
97 |
-
# client_name: str,
|
98 |
-
# system_prompt: str,
|
99 |
-
# num_retrieved_docs: int = 10,
|
100 |
-
# num_docs_final: int = 9,
|
101 |
-
# temperature: float = 0,
|
102 |
-
# max_new_tokens: int = 1024,
|
103 |
-
# top_p: float = 1.0,
|
104 |
-
# top_k: int = 20,
|
105 |
-
# penalty: float = 1.2,
|
106 |
-
# ):
|
107 |
-
# print(f"Message: {message}")
|
108 |
-
# print(f"History: {history}")
|
109 |
-
|
110 |
-
|
111 |
-
# # Build the conversation prompt including system prompt and history
|
112 |
-
# conversation = system_prompt + "\n\n" + "For Client:" + client_name
|
113 |
-
# for user_input, assistant_response in history:
|
114 |
-
# conversation += f"User: {user_input}\nAssistant: {assistant_response}\n"
|
115 |
-
# conversation += f"User: {message}\nAssistant:"
|
116 |
-
# question = message
|
117 |
-
# answer = client.predict(question=question, api_name="/answer_with_rag")
|
118 |
-
# # debug 092624
|
119 |
-
# print("The Answer in stream_chat_with_rag:")
|
120 |
-
# print(answer)
|
121 |
-
|
122 |
-
# # Update the conversation history
|
123 |
-
# history.append((message, answer))
|
124 |
-
# return answer
|
125 |
-
|
126 |
-
|
127 |
# Function to handle PDF processing API call
|
128 |
def process_pdf(pdf_file):
|
129 |
return client.predict(
|
@@ -148,7 +106,7 @@ CSS = """
|
|
148 |
"""
|
149 |
|
150 |
# Title for the application
|
151 |
-
TITLE = "<h1 style='text-align:center;'>
|
152 |
|
153 |
# Create the Gradio Blocks interface
|
154 |
with gr.Blocks(css=CSS) as demo:
|
|
|
6 |
HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
|
7 |
|
8 |
# Initialize the Gradio Client for the specified API
|
|
|
9 |
client = Client("on1onmangoes/CNIHUB101324v10", hf_token=HF_TOKEN)
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Update the conversation history within the function.
|
12 |
# Return the updated history along with any other required outputs.
|
|
|
72 |
# Step 2: Clean up formatting by replacing escaped newline characters
|
73 |
formatted_answer = answer_before_docs.replace("\\n", "\n").strip()
|
74 |
|
75 |
+
# Step 3: Remove potential starting and ending artifacts like (' and ,) if present
|
76 |
+
if formatted_answer.startswith("(\"") and formatted_answer.endswith("\","):
|
|
|
77 |
formatted_answer = formatted_answer[2:-2].strip()
|
78 |
|
79 |
+
# Optional: Add a prefix for clarity
|
80 |
formatted_answer = "Co-Pilot: " + formatted_answer
|
81 |
|
82 |
return formatted_answer
|
83 |
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
# Function to handle PDF processing API call
|
86 |
def process_pdf(pdf_file):
|
87 |
return client.predict(
|
|
|
106 |
"""
|
107 |
|
108 |
# Title for the application
|
109 |
+
TITLE = "<h1 style='text-align:center;'>CNI RAG QA v0</h1>"
|
110 |
|
111 |
# Create the Gradio Blocks interface
|
112 |
with gr.Blocks(css=CSS) as demo:
|